Skip to content

Instantly share code, notes, and snippets.

@pol
Created January 11, 2011 01:42
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save pol/773849 to your computer and use it in GitHub Desktop.
Save pol/773849 to your computer and use it in GitHub Desktop.
Set the background color of iTerm based on RAILS_ENV
#!/usr/local/bin/bash
set_term_bgcolor(){
local R=$1
local G=$2
local B=$3
/usr/bin/osascript <<EOF
tell application "iTerm"
tell the current terminal
tell the current session
set background color to {$(($R*65535/255)), $(($G*65535/255)), $(($B*65535/255))}
end tell
end tell
end tell
EOF
}
#
if [[ "$@" =~ production.server ]]; then
set_term_bgcolor 20 0 0
elif [[ "$@" =~ staging.server ]]; then
set_term_bgcolor 0 20 0
fi
ssh $@
set_term_bgcolor 0 0 0
@kai-inokuchi
Copy link

kai-inokuchi commented Jun 6, 2016

Thank you for sharing this.
Unfortunately, I found that your AppleScript doesn't work in iTerm2 Build 3.0.0.
I fixed the script like this and it's been working:

tell application "iTerm"
  tell the current window
    tell the current session
      set background color to {$(($R*65535/255)), $(($G*65535/255)), $(($B*65535/255))}
    end tell
  end tell
end tell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment