Production is Red, Development is Blue

Paul Oswald tweeted a great idea for a productivity hack based on sensory feedback:

Example scenario: ssh into your production machine, then have your terminal automatically sets its background color to red. Exit back to your development machine, and the background color automatically reverts to blue.

Jed Schmidt chimed in with a solution:

I hacked up a bash script to implement their idea.

This script only works with the Mac OS X Terminal app, not iTerm as Jed suggested, but it could be modified to work with any terminal app that supports AppleScript.

The concept of sensory feedback could be extended further, too. I think it’d be neat to play a specific sound clip when you ssh into your production machine. Sort of like Happy Git Commits.

The code:

# ssh into a machine and automatically set the background
# color of Mac OS X Terminal depending on the hostname.
# Installation:
# 1. Save this script to /some/bin/ssh-host-color
# 2. chmod 755 /some/bin/ssh-host-color
# 3. alias ssh=/some/bin/ssh-host-color
# 4. Configure your host colors below.
set_term_bgcolor() {
   local R=$1
   local G=$2
   local B=$3
   /usr/bin/osascript <<EOF
tell application "Terminal"
   tell window 0
      set the background color to {$(($R*65535/255)), $(($G*65535/255)), $(($B*65535/255))}
   end tell
end tell
# Host-specific background colors.
if [[ "[email protected]" =~ ]]; then
   set_term_bgcolor 127 0 0
elif [[ "[email protected]" =~ ]]; then
   set_term_bgcolor 0 127 0
ssh [email protected]
# Default background color.
set_term_bgcolor 34 79 188