(* Script Name: Color Terminal by Server Scripted By: Matt Petrowsky at http://www.filemakermagazine.com/ This script uses the hostname tool to color the frontmost Terminal window. Special notes: 1) You need to be inside a shell, not within an application (e.g. vi, emacs, pine...)! 2) The script parses the hostname using sed so you'll need to make sure your prompt has an identifiable character. Here is an example of my PS1 line in my .bash_profile (PS1 is bash, sh and ksh specific, tcsh and csh are different) PS1='[\u:\w] % ' Notice I use the brace character - which is in the second sed expression. If you don't know sed then now's a good time to learn. ;) See the bottom comments about PS1. - enjoy *) -- Set your favorite colors, the easiest way to adjust is with -- Terminal's window settings and then use get background color set light_green to {-3746, -1989, -5668} set light_tan to {-2033, -3016, -7800} set light_blue to {-7822, -3960, -2093} set light_orange to {-1995, -5865, -12821} -- Set the critera used to match. Typically server names either fqdn's or local names set my_hosts to {¬ {host:"mymac.local", color:light_tan, location:"You're Home Dude"}, ¬ {host:"speedy.gonzales.com", color:light_green, location:"Speedy Server"}, ¬ {host:"bdove.somechurch.org", color:light_blue, location:"Church Server"}, ¬ {host:"cvs", color:light_orange, location:"Your local linux box"} ¬ } tell application "Terminal" do script "hostname" in window 1 delay 0.5 set terminal_text to contents of window 1 set cmd to "echo " & quoted form of terminal_text & " | tr -d '\\n' | sed -e 's/^.*hostname//' -e 's/\\[.*$//'" end tell -- Older method that uses window title and not hostname tool --set cmd to "echo '" & win_title & "' | sed -E -e 's/^[^@]+//' -e 's/:.*$//'" set server_name to do shell script cmd repeat with server in my_hosts if host of server is equal to server_name then tell window 1 of application "Terminal" set background color to color of server -- Uncomment the following for fun --display dialog location of server buttons {"OK"} default button "OK" end tell end if end repeat (* #PS1 is your prompt. Variables are #\s = software #\v = version #\u = user #\h = host #\w = working directory #% = shell (user or root) PS1='[\u:\w] % ' *)