Mac OS X change the terminal window title

Contributor Icon Contributed by macster Date Icon September 22, 2004  
Tag Icon Tagged: Apple Mac

The title of the Mac OS X terminal window can easily be changed. This can be useful when running a script or when using multiple terminal windows for different purposes to easily identify them when switching between applications and windows.


In the terminal window, from a bash prompt (the default shell) or in a bash shell script, use the following command to change the terminal window title to Tech-Recipes rules:

echo -n -e "\033]0;Tech-Recipes rules\007"

You can place (just about) any text in place of Tech-Recipes rules including the contents of a variable. For example:

name=`hostname`
echo -n -e "\033]0;$name\007"

This will change the title of the terminal to the hostname of the computer running the shell.

Previous recipe | Next recipe |
 
  • des09
    How would you set the tab title when running multiple tabs?
  • luca
    Thanks, works like a charm. However, it doesn't change the title of a tab, just that of the main windows in which many tabs are contained - so it's useless to be able to see at a glance which terminal is the one you're looking for.
  • CeriDavies
    Perfect, I put this in my .bashrc and the title changes on each tab as I login

    echo -n -e "\033]0;`hostname`\007"

    The only problem I have is that it doesn't change back, when I get logged out, so I have an alias to reset it...

    alias sett="echo -n -e "\033]0;`hostname`\007"
  • CeriDavies
    I put this in my .bashrc
    echo -n -e "\033]0;`hostname`\007
    Then on each tab as I log into a different machine (It has to have that line in the .bashrc of the user/machine I'm logging into) it sets the title as I log in to the machine, so all the tabs are correct.
    And to recover on logout, I put this in the .bash_logout:

    prev=`who am i | sed -e "s/.*(\(.*\))/\1/"`
    if test ! x$prev = x
    then
    echo -n -e "\033]0;$prev\007"
    fi





    alias sett="echo -n -e "\033]0;`hostname`\007"
blog comments powered by Disqus