Coder's Corner: Dynamically Setting Terminal's Window Color In OS Xby Ash White 02.20.2008 With this little gem of a script, you can change Terminal's background color based on the action you are performing: osascript -e 'tell application "Terminal" to set background color of window 1 to {45000, 0, 0, 50000}' This will set the background color of the frontmost Terminal window to a transparent
red.
The coolest example (IMHO) and my main use for it is for differentiating SSH sessions - you
can easily define certain colors to be associated with specific servers. This becomes especially
useful when used with Exposé. You can achieve this by creating an alias that assigns the
window color, executes the ssh client, then switches back to the original window color. Here's an
example:
alias term.red='osascript -e "tell
application "Terminal" to set background color of window 1 to {45000, 0, 0, 50000}"'
alias term.normal='osascript -e "tell
application "Terminal" to set background color of window 1 to {0, 0, 0, 50000}"'
alias myserver='term.red; ssh 12.34.56.78;
term.normal;'
Now, issuing myserver will automagically switch the active Terminal window to red, SSH to the server, and then immediately switch back once the connection is closed. Under the hood, the osascript command
is actually telling OS X to execute the AppleScript string found following the -e flag. This is a
nifty little tool in and of itself, in my opinion. The four values in braces are the RGB and alpha
values for the color. It looks like the expected values are 0 - 65535 (16 bits)
|
|
Comments [post a comment]
I had to change "Terminal" to "Terminal" when I put this in my .bash_profile. Also, if you want to change the text color as well, do:
osascript -e "tell application "Terminal" to set normal text color of window 1 to { 65535, 65535, 65535}"'
which sets the text color to white.
Posted By:
Curtis [Website]
02/22/2008
10:28 AM
I guess this comment form has strip slashes, you have to escape the quotes in "Terminal" by putting a backslash before each one.
Posted By:
Curtis [Website]
02/22/2008
10:29 AM