Terminal scripting in 10.5

Terminal in 10.5 has seen some great scripting improvements to match its additional functionality. Occasionally I have several Terminal sessions with some ssh'd remote servers and then I forget which Terminals are local and which are remote.

Here is a simple little command-line AppleScript that will let you set an individual Terminal's style from the command line;

(2009-09-01: updated for Snow Leopard) setterminalstyle-v2

Put the script in your PATH somewhere and then add a ssh function in your .zshrc, or equivalent:

# Show remote Terminal sessions with a different style.

# TERM_PROGRAM doesn't get set if we are logged in remotely,

# but then the originating Terminal could have done this (hopefully).

if [ "$TERM_PROGRAM" = "Apple_Terminal" ]; then

  function ssh {

    SetTerminalStyle ssh

    /usr/bin/ssh "$@"

    SetTerminalStyle default

  }

fi

Finally, create a ssh Settings entry in Terminal's preferences:

Terminal-ssh-settings-set.png

Other obvious commands for this include sudo and su.Using RPROMPT and Terminal's processes scripting property on tab it might be possible to get this to work without the function wrappers, but executing the AppleScript on every command was a little too slow for my taste.