save pdf by AppleScript

  • 投稿日:
  • by

WEBペー
ジを200枚ほどPDFに保存する必要ができた。
ここは AppleScriptで以下のようなスクリプトを書いた。

いろいろ探したけど、あまりかっこいいものは書けなかった。
キーボードの入力をシミュレートするなんて...

サンプルは、サイト「noname.com」の「test.cgi」を引数「id=数値」の形式で呼び出すもの。
数値は、「1」から「178」まで。適当に修正して利用する。

tell application "Safari"
        activate
 
        set n to 1
        repeat
                if n > 178 then exit repeat
                set xURL to "http://noname.com/test.cgi&id=" & n as string
                set n to n + 1
                open location xURL
                delay 2
                tell application "System Events"
                        tell application process "Safari"
 
                                keystroke "p" using command down
                                delay 1
                                keystroke tab using shift down
                                keystroke tab using shift down
                                keystroke tab using shift down
                                keystroke (ASCII character 31)
                                keystroke (ASCII character 31)
                                keystroke (ASCII character 31)
                                keystroke return
                                keystroke return
                                delay 2
                                keystroke "w" using command down
                                delay 2
                        end tell
                end tell
        end repeat
end tell