Skip to content

Instantly share code, notes, and snippets.

@sirkkalap
Created June 10, 2014 08:56
Show Gist options
  • Save sirkkalap/c740fb287b701c8565f0 to your computer and use it in GitHub Desktop.
Save sirkkalap/c740fb287b701c8565f0 to your computer and use it in GitHub Desktop.
Screenshot in scale 50% (for Retina)
# the path where screenshots to save
SS_PATH="/Users/petrisi/Desktop"
# if you want to save them to your desktop, SS_PATH should be "/Users/YOURNAME/Desktop"
# a variable of unix timestamp for screenshot file name
DATE=$(date +%Y-%m-%d)
TIME=$(date +%H.%M.%S)
NOW=""
SS_BASENAME="$SS_PATH/Näyttökuva $DATE kello $TIME"
# execute screen capture command, screenshot$NOW.png is the name of file
screencapture -i -r "$SS_BASENAME@2X.png"
# then downscale the high resolution screenshot to 50% by imagemagick
# /usr/local/bin/convert $SS_PATH/screenshot$NOW@2X.png -resize 50% $SS_PATH/screenshot$NOW@1X.png
# check if screenshot is existing
if [ -f "$SS_BASENAME@2X.png" ]; then
# get the 50% width of screenshot by sips
WIDTH=$(($(sips -g pixelWidth "$SS_BASENAME@2X.png" | cut -s -d ':' -f 2 | cut -c 2-)/2))
# scale down by sips
sips --resampleWidth $WIDTH "$SS_BASENAME@2X.png" --out "$SS_BASENAME.png"
# copy small one to clipboard by applescript
osascript -e "set the clipboard to POSIX file \"$SS_BASENAME.png\""
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment