Skip to content

Instantly share code, notes, and snippets.

@tuhaihe
Created June 8, 2014 12:10
Show Gist options
  • Save tuhaihe/0bb13ec1b6a2710b360a to your computer and use it in GitHub Desktop.
Save tuhaihe/0bb13ec1b6a2710b360a to your computer and use it in GitHub Desktop.
Macbook-Retina-Screenshot
# the path where screenshots to save
SS_PATH="/Users/wangdj/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
NOW=$(date +%s)
# execute screen capture command, screenshot$NOW.png is the name of file
screencapture -i -r $SS_PATH/screenshot$NOW@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_PATH/screenshot$NOW@2X.png ]; then
# get the 50% width of screenshot by sips
WIDTH=$(($(sips -g pixelWidth $SS_PATH/screenshot$NOW@2X.png | cut -s -d ':' -f 2 | cut -c 2-)/2))
# scale down by sips
sips --resampleWidth $WIDTH $SS_PATH/screenshot$NOW@2X.png --out $SS_PATH/screenshot$NOW@1X.png
# rm orginal pic file
rm $SS_PATH/screenshot$NOW@2X.png
# copy small one to clipboard by applescript
osascript -e 'set the clipboard to POSIX file "'$SS_PATH/screenshot$NOW@1X.png'"'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment