Athens Exchange
  • home
  • daily
  • athens
  • music
  • film & tv
  • food
  • sports
  • sci & tech
  • popfest 2008
 
Thursday, August 21, 2008
Weather: , °
search:  
Post a Comment        E-mail this Article to a Friend        Join the List        AddThis Social Bookmark Button

Coder's Corner: Dynamically Setting Terminal's Window Color In OS X

by 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

Name
Email
URL
Body
Are you human?
  • More Technology
    Coder's Corner: Maintaining Clean URLs With mod_rewrite
    by Ash White
    05.10.2008

    Mark Spencer's Asterisk Challenges Traditional Telecom Technology
    by Allison Brill
    04.06.2008

    Shhhh! The red light is on....
    by Allison Brill
    03.31.2008

  • More From Ash White
  • [Recorded] What Transition? Moving From PowerPC Mac To Intel Core 2 Duo Mac
  • [Recorded] Rhabdophobic, Just Passin' Through


Contact • Contribute • Privacy Policy

© 2008 Athens Exchange
Powered By Boxkite Media