Skip to content

Mac OS X Terminal: visual indication for your ssh connection

2011 January 14
by tobi

Here’s a HowTo for a nice visual indication to see quickly if your Mac OS X Terminal is running which ssh connection.

The trick is to change your Terminal Theme before you ssh and change it back afterwards.

1. Create Theme:
got to Terminal -> Preferences -> Settings create a new theme (or copy existing one) and adjust to your needs, e.g. a light red background etc. Give it a nice name e.g. “SSH-Theme”

2. Add this function to your .bashrc

function tabc() {
NAME=$1; if [ -z "$NAME" ]; then NAME="Default"; fi
osascript -e "tell application \"Terminal\" to set current settings of front window to settings set \"$NAME\""

“Default” is my default Terminal theme, name this whatever u have

tabc SSH-Theme #switch to theme with name
tabc #switch to default theme

3. Create alias to ssh to server:

alias sshmyserver="tabc SSH-Theme; ssh; tabc"

That’s it – your are done! Now, if you type sshmyserver, your Terminal color will change, ssh will start, and when you end ssh, everything will be back again..

Btw. for Terminal on Mac OS X, I very recommend Visor – a quake like console


That’s how you do it with iTerm:

function tabc() {
COLOR=$1; if [ -z "$COLOR" ]; then COLOR="{0, 7722, 9941}"; fi
osascript -e "tell application \"iTerm\" to set background color of current session of current terminal to $COLOR"

alias sshmyserver="tabc '{18000, 2500, 2500}'; ssh; tabc"

11 Responses
  1. admin permalink*
    July 18, 2012

    btw. I found this gist to even color your tabs:

  2. December 7, 2011

    Thank you very much. After having an oh-crap-what-server-was-that-oh-phew moment earlier today this will be a lifesaver.

  3. June 18, 2011

    … or. (doh!) … change the word ‘Default’ to the name of the default theme. tabc alone works fine then

    Nb. tabc “Red Sands” – quotes needed if space

  4. June 18, 2011

    In .bash_profile add this:

    if [ -f ~/.bashrc ]; then
    source ~/.bashrc

    This checks for .bashrc and loads it if needed

    In .bashrc add this

    2> /dev/null on the same line as NAME\”” – this stops osascript errors appearing on later OS X (due to 64/32 bit conflict)

    Add this
    alias web=”tabc SSH; ssh user@server ; tabc Pro”

    (Change SSH and Pro as need be)

    Honestly, you can put it all into .bash_profile, as OS X runs .bash_profile on each tab

    I found tabc on its own did not go back to the default, hence ‘Pro’

  5. Natalie permalink
    May 27, 2011

    Yes it does, thank you. But it only works for that terminal session, is there a way to do it so I don’t have to run the ‘source’ and ‘alias’ command each time I open a new terminal window?

  6. tobi permalink*
    May 26, 2011

    uhtsch: well then try:

    “source ./bashrc”

    does it work now? If yes, you file is nevered loaded. Maybe use .bash_profile instead of .bashrc then… success??

  7. Natalie permalink
    May 25, 2011

    Hi Tobi,

    Yes, I removed those last two lines and it’s still not changing to the SSH theme I specified. Eek! *head scratching*

    I ran the ‘tabc’ command and it returns ‘-bash: tabc: command not found’ (I created the .bashrc file in my home directory ~/). Don’t know why the demo code won’t even run.

  8. tobi permalink*
    May 25, 2011

    Try removing last two Lines. That’s just demo code – does it work now??

  9. Natalie permalink
    May 24, 2011

    Hi, I’m able to ssh to my server when I type ‘sshmyserver’ but the terminal isn’t changing theme. I get “-bash: tabc: command not found”….

    My .bashrc looks like this:

    function tabc() {
    NAME=$1; if [ -z "$NAME" ]; then NAME="Home"; fi
    osascript -e "tell application \"Terminal\" to set current settings of front window to settings set \"$NAME\""
    tabc SSH-Dev #switch to theme with name
    tabc #switch to default theme

  10. April 2, 2011

    Thank you! Can’t believe I’ve been changing my Terminal theme manually for 2 years..

Trackbacks and Pingbacks

  1. Change your terminal theme when you ssh into a server | A Tempest of Thoughts

Comments are closed.