Coloring an OSX Terminal window based on an ssh connection?
May 15, 2008 12:45 PM   Subscribe

My career involves me using OSX Terminal ssh'd into other servers. Often, I have multiple ssh connections open, sometimes two or three to the same server. I can't bring myself to use tabs. Is there anything that can automatically be done to automatically color/title my terminal windows once I ssh into them?

Even nicer would be a spotlight command to launch terminal and connect to a terminal. Then, the color/background image (and window title) would change based on my ssh connection, depending on server name/address, production vs qa vs dev, etc. We're talking about 10 diff. servers overall and often I have two or three terminals open to the same server.

Is this the reason I've been needing to finally delve into Applescript, or does a solution already exist?

I would consider installing QS if a solution exists. If it helps, I dont do a whole lot locally from the OSX terminal, its always ssh.
posted by neilkod to Computers & Internet (7 answers total) 7 users marked this as a favorite
You might want to check out iTerm ( I've heard good things about it, and the page seems to indicate that the tabs can change color depending on activity.
posted by kbanas at 12:58 PM on May 15, 2008

You can do this using some BASH scripting, assuming that's the shell you're using. Send me a mefi mail and I can provide some sample code to get you started in the right direction.
posted by zap rowsdower at 1:01 PM on May 15, 2008

If you go the settings section of Terminal's Preferences, you can create a setting for each server that has your preferred colors. Under the shell tab, you can have it run a command right away instead of just launching a local shell. Then, you can create new windows with each setting.

You could then use AppleScript to create little apps to run these from the Finder or wherever. I'm not AppleScripter though, and Terminal isn't recordable, so I can't help you there.
posted by mkb at 1:03 PM on May 15, 2008

Yes, just click the "+" under the list in the "Setting" pane of the preferences window, click the "Window" tab to fill in the window title and select the color and transparency, and the "Shell" tab to set the command "ssh hostname". Then I set keyboard macros for each of the items in Terminal's "Shell" menu.
posted by nicwolff at 1:43 PM on May 15, 2008 [1 favorite]

I would have written a bash script to do it as well (which, assuming you log into the machines as the same user, has the added advantage of working on ANY machine, as it sets the colour on the server), but to be honest, nicwolff and mkb's solution sounds easier... :)

Nonetheless, if you need the bash details, let me know!
posted by ranglin at 2:22 PM on May 15, 2008

mkb has it, above. I have different settings for the dozen or so servers that I ssh into on a regular basis. Each of these have a different background color, some have different fonts or sizes, and all of them have "ssh <user@server>" as the shell command. Under 10.4, these preferences were stored as files that could be indexed through Quicksilver, but I haven't been able to do this under 10.5. Instead, the different preferences show up in the right-click menu for Terminal's Dock icon, under "New Window…". That's how I do it, anyway.
posted by eafarris at 5:52 PM on May 15, 2008

Leopard's Terminal has "window groups", which are named collections of tabs. You can set up a window group with one tab for each SSH connection.

As for the colorization part, Terminal can't colorize tabs, and the old trick to set the terminal title using ANSI escape codes doesn't affect the tabs. This trick is the only way I know to customize the tab name -- basically, you create a link (hard, not symbolic) to a script named whatever you want in the tab. Not pretty, but works.
posted by gentle at 7:08 PM on May 17, 2008

« Older Help me improve an employee's writing skills.   |   They couldn't have asked us LAST week? Newer »
This thread is closed to new comments.