Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@kainoku

This comment has been minimized.

Copy link

@kainoku kainoku 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
You can’t perform that action at this time.