Skip to content

Instantly share code, notes, and snippets.

@mmenozzi
Created August 2, 2013 06:45
Show Gist options
  • Save mmenozzi/6137938 to your computer and use it in GitHub Desktop.
Save mmenozzi/6137938 to your computer and use it in GitHub Desktop.
Script that resizes and crop an image and then sets as background for iTerm
#!/bin/bash
# Script that resizes and crop an image and then sets as background for iTerm
# First, check to see if we have the correct terminal!
if [ "$(tty)" == 'not a tty' ] || [ "$TERM_PROGRAM" != "iTerm.app" ] ; then
exit $?
fi
# Console dimensions
# Generate dimension based on screensize
H=$((1440/178*`stty size | cut -d ' ' -f2`))
V=$((900/47*`stty size | cut -d ' ' -f1`))
DIMENSIONS=$H"x"$V
function set_bg {
local tty=$(tty)
osascript -e "
tell application \"iTerm\"
repeat with theTerminal in terminals
tell theTerminal
try
tell session id \"$tty\"
set background image path to \"$1\"
end tell
on error errmesg number errn
end try
end tell
end repeat
end tell"
}
convert /path/to/source-image.jpg -resize "$DIMENSIONS^" -gravity center -crop $DIMENSIONS+0+0 +repage /tmp/iterm-bg-$DIMENSIONS.jpg
set_bg "/tmp/iterm-bg-$DIMENSIONS.jpg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment