OSXでスクリーンキャプチャをとるシェルスクリプトです。Retina対応版というのは具体的には、キャプチャした画像が72dpi以外なら72dpiになるようにリサイズする処理を入れています。
capture.sh
#!/bin/sh
f=${1:-~/Desktop/capture-`date '+%Y%m%d-%H%M%S'`.png}
/usr/sbin/screencapture -i $f 2>/dev/null
/usr/bin/sips -g dpiWidth -g dpiHeight -g pixelWidth -g pixelHeight $f |
/usr/bin/awk -v imagefile=$f '
$1=="dpiWidth:" {dpiWidth = $2}
$1=="dpiHeight:" {dpiHeight = $2}
$1=="pixelWidth:" {pixelWidth = $2}
$1=="pixelHeight:" {pixelHeight = $2}
END {
if (dpiWidth != 72 || dpiHeight != 72) {
w = int(pixelWidth * 72 / dpiWidth)
h = int(pixelHeight * 72 / dpiHeight)
cmd = sprintf("/usr/bin/sips %s -s dpiWidth 72 -s dpiHeight 72 -z %d %d >/dev/null 2>&1", imagefile, h, w)
system(cmd)
}
}
'
Ben Alman » Fixing "Retina" Image Scaling with Gyazo の記事と dotfiles/bin/resample-dpi at master · cowboy/dotfiles · GitHub のスクリプトを参考に作りました。ありがとうございます。