Swombat

wombat + s 
« Back to blog

Setting up Terminal.app with transparent background colours via AppleScript

So, you want to have transparent background colours, specific to each server, on your terminal, so that you won't confuse your production server with your local test VM?

Easy.

Of course, you could follow this tutorial or this tutorial to set your background colour directly via AppleScript. Unfortunately, there's a problem with that: in their infinite wisdom, Apple decided to remove the transparency argument from the "set background color" hook, so that whenever you set the colour programmatically, you'll lose the terminal transparency.

And what's the point of having a shiny new glossy macbook pro if you can't have transparent terminal windows, eh? What would be the point of that? We demand our transparency! 

Some heretics might suggest doing something like this, which basically involves getting AppleScript to actually open up the window settings and click on the sliders to enable the transparency. Oh, and each step is separated from other steps by a 1 second delay. Insane! We demand not only transparency, we demand instantaneous transparency. We programmers are a busy lot, and have no time to wait several seconds for a dumb terminal to adjust its sliders.

Well, here it is.

Step 1: Create a Terminal.app profile that has all the transparency you want, and all the other tidbits set correctly, in the "Settings" tab of the Terminal.app settings. Call this profile 'Black'.

Step 2: Duplicate that profile, and adjust the colour so it's a nice dark red. Call this one 'Red'.

Step 3: Duplicate 'Red' a bunch of times and change the colour each time, until you have all the essential colours... Red, blue, cyan, green, purple, and yellow.

Step 3: Create a bunch of aliases in your .bashrc or your .bash_aliases, that do something like this:

alias t.green='echo "tell application \"Terminal\" to set current settings of first window to settings set 4" | osascript'

Since there's no way to tell "setting set"s by name, you'll unfortunately have to play around a little bit until you match up the alias names with the profiles.

Done!

You can now prefix aliases that connect to your favourite servers with "t.red" or "t.blue" or whatever strikes your fancy. For example:

alias srv_production="t.red; ssh production"

Ain't that a beauty?

Daniel

Comments (0)

Leave a comment...

 
Got an account with one of these? Login here, or just enter your comment below.
Posterous-login    twitter