mikepk.com about current projects contact

Launch OS X Terminal With Specific Settings From Command Line

March 3, 2011

Back when I did most of my development using Linux, I would often create scripts that would launch xterms with specific settings and colors to "color code" my development environment. A particular terminal connected to a host might be blue, to give me a strong visual cue what environment I was typing commands in.

An old tip that I find useful (especially when you're sleep deprived) is to color code a terminal connected to an important (say, live) site in a warning color like red or yellow. I find it makes it less likely you'll do the inevitable fumbly-finger destructive command by accident (DROP TABLE important_stuff, or rm * in some critical live site path).

I decided I wanted to recreate something similar in OS X and it took me a few searches to find a solution so I thought I'd share. This is in OS X Snow Leopard, so YMMV.

First create your Terminal settings using the Inspector in the Terminal app. Screen shot 2011 03 03 at 2 59 45 PM Select your colors, initial command, fonts, size, etc... Then launch a terminal with those settings. Select Shell » Export Settings... and chose a filename. This will save an apple .plist, XML file with a .terminal extension. You can also use the "Gear" icon on the Inspector settings panel and chose Export... to do the same thing.

Since it's just an XML file you can use a text editor and edit this file to change the settings if you want. Terminal2 There are two nice things that you can do with this file, first you can double click on it to launch a terminal with those particular terminal settings. The other thing is that now you can write scripts to open those particular terminal settings using the open command, just call the .terminal file like so: open ~/Desktop/my_red_warning_terminal.terminal. Voila.

Note: Obvisouly another way to do this is to run the Apple Xserver and actually use xterms, but I kind of like the Apple Terminal and some of it's behaviors.