画面キャプチャできるApplescript

画面キャプチャのショートカット「command+shift+3, command+shift+4」と同じで、それ以上のオプションを付けられるApplescript。

基本

do shell script "screencapture ~/Desktop/" & "imgk_001.png"

これでモニタ画面をキャプチャできます。
ファイルはデスクトップに保存されます。
しかし、ツールバーのある画面しかキャプチャできません。その点ではショートカット「command+shift+3」の方が全モニタをキャプチャできるので優秀。
このコードではファイル名は固定で、同名ファイルがある場合は上書きされます。

時刻をファイル名に入れる

set kp_file to "img_" & (getT() as string) & ".png"
do shell script "screencapture ~/Desktop/" & kp_file

on getT()
set localdate to (current date)
set y to year of localdate as number
set m to month of localdate as number
set d to day of localdate as number
set h to hours of localdate as number
set mi to minutes of localdate as number
set ss to seconds of localdate as number
if m < 10 then
set m to "0" & (m as string)
end if
if d < 10 then
set d to "0" & (d as string)
end if
if h < 10 then
set h to "0" & (h as string)
end if
if mi < 10 then
set mi to "0" & (mi as string)
end if
if ss < 10 then
set ss to "0" & (ss as string)
end if
set msg to y & m & d & h & mi & ss
end getT

2016年5月31日18時11分1秒に使うとimg_20160531181101.pngの名前で保存されます。

 参考サイト

自動キャプチャ

tell application "Safari"
activate
delay 0.5
end tell
set msg to 1
repeat 16 times
if msg < 10 then
set kp_file to "img_" & "00" & (msg as string) & ".png"
else if msg < 100 then
set kp_file to "img_" & "0" & (msg as string) & ".png"
else
set kp_file to "img_" & (msg as string) & ".png"
end if
do shell script "screencapture ~/Desktop/" & kp_file
tell application "System Events"
tell application process "Safari"
delay 0.1
keystroke (ASCII character 28)
delay 0.9
end tell
end tell
set msg to msg + 1
end repeat

連番で自動にキャプチャします。
Safariなど操作したいアプリを決めて下さい。
repeat 数値 timesでキャプチャ回数を決めます。
delay 数値でキャプチャ間隔(秒)を決めます。
keystrokeはキー操作を加えたいときに使用します。

入力値操作
ASCII character 30
ASCII character 29
ASCII character 31
ASCII character 28

オプション付加

do shell script "screencapture  ~/Desktop/" & "imgk_001.png"

に以下の文字を入れる事でオプションを付けられる。OSバージョンによって使えない物もある。

入力値操作
-Cマウスカーソルも撮影
-icommand+shift+4
-Wウィンドウ選択(余白が大きく付く)
-xシャッター音なし
 参考サイト
2016/5/31

 PC表示に切替     スマホ表示に切替     タブレット表示に切替