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.
-
Should note that there's nothing OS X specific about this -- the answer will work on pretty much any terminal. – Andrew Aylett Feb 06 '10 at 11:22
-
Is it Bash-specific then? – Dan Rosenstark Feb 06 '10 at 14:55
-
@Andrew Aylett, so the script I put in my answer (below) will work on the linux distros, too? – Dan Rosenstark Feb 06 '10 at 18:20
-
Yes, it should work anywhere (with an sh-derived shell) that uses unix-y terminals. – Andrew Aylett Feb 11 '10 at 22:02
7 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.
- 2,996
- 22
- 20
-
Excellent. Could you include a sample script (like this? `echo -n -e "\033]0;$1\007"`) in your answer so I can mark it best answer, please? – Dan Rosenstark Feb 06 '10 at 09:15
-
2*printf* may be more reliable: `printf "\033]0;%s\007" "$title_variable"` (the various options and behaviors of *echo* are not the same across all systems, shells, or even shell options) Also, variable assignments in *bash* should not have spaces around the equals sign. – Chris Johnsen Feb 06 '10 at 12:03
-
1I used $* and within a function, so I wouldn't have to quote my title string. – BeepDog Jul 01 '15 at 21:39
-
Is there a way to change the title from within a C program? The program I'm thinking about is running animation based on ncurses.h so I am not sure how to echo to the terminal :-( – phs Nov 02 '15 at 17:23
-
-
Adding 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.
- 101
- 2
- 4
-
why is it a problem if you have many functions in .profile? is there a limit? – tgkprog Jun 04 '13 at 14:22
-
1
-
2
-
-
You can also add it using `sudo nano /etc/bashrc`. This should run for all the users. Restart terminal session or do `source /etc/bashrc` to apply your changes. – Eugene Kulabuhov Jun 26 '17 at 18:50
-
-
To add to this great suggestion, I opted to use the variable `$*` instead of `$1`, so that the title function can be used without having to quote the argument, e.g. `title hello world this is my tab title` – dancow Jun 17 '20 at 23:26
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)
- 6,388
- 13
- 59
- 95
-
1If you're on one of those newer versions of OS X you may to do `/usr/local/bin/title` instead. – Samie Bencherif Jun 09 '17 at 03:02
As 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.
- 14,636
- 2
- 35
- 44
- 31
- 1
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 tell
this will set the name of the new tab to WorkerTab1 and then perform other commands like "cd" , etc.
- 21
- 1
On OS X, terminal preferences are stored in ~/Library/Preferences/com.apple.Terminal.plist.
The terminal's title is stored in the WindowTitle preference.
- 111
- 3
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]"