Last active
December 15, 2015 04:59
-
-
Save tgck/5206103 to your computer and use it in GitHub Desktop.
ファイルのキャプチャをバッチ処理的に作成するスクリプト
AppleScript/MacOS X: 10.6.8/AppleScript Editor: 2.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set whichUrl to 1 | |
-- 画面サイズを取得 | |
tell application "System Events" | |
set {rightLimit, bottomLimit} to size of scroll area 1 in process "Finder" | |
end tell | |
-- 対象ファイルの数を取得 | |
-- TODO: Finder選択項目でフォルダ内容を取得 もしくはドロップしたファイルを対象とする | |
tell application "TextEdit" | |
set theCount to the count of paragraphs of front document | |
end tell | |
-- ファイルごとの処理 | |
repeat theCount times | |
tell application "TextEdit" | |
set currentUrl to paragraph whichUrl of front document as text | |
end tell | |
do shell script "open " & currentUrl | |
delay 1 | |
tell application "Pd-extended" | |
activate | |
tell application "System Events" | |
tell process "Pd-0.44.0-extended-20130203" | |
--return properties of windows | |
--set position of window 1 to {0, 21} -- 左上に揃える場合 | |
--中央に揃える(cropの仕様への対策) | |
set ourWindowSize to size of window 1 | |
set position of window 1 to {(rightLimit - (item 1 of ourWindowSize)) / 2, (bottomLimit - (item 2 of ourWindowSize)) / 2} | |
end tell | |
end tell | |
-- キャプチャ | |
set picturePath to ((POSIX path of (path to desktop)) & "out_" & whichUrl & ".png") as string | |
do shell script "screencapture -tjpg " & quoted form of picturePath | |
-- do shell script "screencapture -tjpg -iW -o " & quoted form of picPath | |
-- iW でウィンドウ指定するのは面倒。 | |
-- ウィンドウを閉じる | |
tell application "System Events" | |
keystroke "w" using {command down} | |
end tell | |
-- スクリーンショットの加工 | |
try | |
tell application "Image Events" | |
launch | |
set this_image to open picturePath | |
crop this_image to dimensions ourWindowSize | |
save this_image with icon | |
close this_image | |
end tell | |
on error error_message | |
display dialog error_message | |
end try | |
end tell | |
-- 次のファイル | |
set whichUrl to whichUrl + 1 | |
end repeat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment