Skip to content

Instantly share code, notes, and snippets.

@drbh
Last active November 9, 2023 10:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drbh/fb2e9ca5455a2bff5cf51ffa3d89a27c to your computer and use it in GitHub Desktop.
Save drbh/fb2e9ca5455a2bff5cf51ffa3d89a27c to your computer and use it in GitHub Desktop.
Programmatically change the background color of iTerm - or set it randomly
set_term_bgcolor(){
local R=$1
local G=$2
local B=$3
/usr/bin/osascript <<EOF
tell application "iTerm"
tell current session of current window
set background color to {$(echo "scale=2; ($1/255.0)*65535" | bc),$(echo "scale=2; ($2/255.0)*65535" | bc),$(echo "scale=2; ($3/255.0)*65535" | bc)}
end tell
end tell
EOF
}
set_random_bgcolor(){
set_term_bgcolor $(echo $(echo 0."$RANDOM")*255 | bc) $(echo $(echo 0."$RANDOM")*255 | bc) $(echo $(echo 0."$RANDOM")*255 | bc)
}
@sarnobat
Copy link

This is great for helping you to come up with new color palettes. I rely on 4-5 different ones and feel like I've run out of options.

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