How can I arbitrarily change the title of a Terminal window in Mac OS X? I have seen this question and this magicwrap thing, but think it's just a simple Mac OS X command.
47 Answers
This article tells you how.
Essentially, you use character sequences echoed to the screen to inform the terminal of what title it should display.
title='My first title'
echo -n -e "\033]0;$title\007"In the above example, whatever the variable title is set to while become the terminal's title. Of course, you could just have the title in the string to echo such as:
echo -n -e "\033]0;My first title\007"But the first way makes it a slightly bit easier to use and/or extend later.
6Adding the following to your ~/.profile will achieve the same effect:
# function for setting terminal titles in OSX
function title { printf "\033]0;%s\007" "$1"
}And then a quick title 'et voila' will sort all your tabs out.
Remix of Dan MgG's answer:
echo -n -e "\033]0;$1\007"Store it in a file called /usr/bin/title (using sudo!) and chmod it to +x. Then from anywhere you can just type
title 'Trying to Figure This GIT Thing Out'and you get a nice little title.
(Syntax may vary if you're not on OSX, if I understand correctly)
1As an alternative to sh-based command line solutions, the OS X Terminal app has a preference to change the title as follows: Under the Terminal->shell menu there is a "edit title" choice, select that and you can change the title easily.
The reply marked as Best answer works fine... this is what i did...
tell application "Terminal" activate do script "echo -n -e \"\\033]0;WorkerTab1\\007\"; cd $HOME/folder1"
end tellthis will set the name of the new tab to WorkerTab1 and then perform other commands like "cd" , etc.
On OS X, terminal preferences are stored in ~/Library/Preferences/com.apple.Terminal.plist.
The terminal's title is stored in the WindowTitle preference.
Thanks for this. I just added a function to my .bashrc:
function stit() { echo -n -e "\033]0;$1\007"
}In my mind "stit" = a convenient shortcut for "set_title". And now when I want to set the title of my windows on the fly, I type:
stit "[new window title]"