07. GUI Scriptingで作業自動化(2)
2013-04-25


本項のスクリプトでは、「メモ書き倉庫」さんの「AppleScriptであれこれする」から以下のハンドラを拝借して外部参照しています。
ここに巡り会ったおかげで、今回の作業は偶然的に成立しました。素晴らしい仕事に感謝します。
[URL]

画像編集の老舗アプリGraphicConverterの機能のひとつに各種バッチ処理があります。画像の縮尺率の数字、4.5とか0.6などクリップボードに入れておいてスクリプト実行するとバッチファイルが書き換わる、そんな用途です。
マウス・キー操作9回をまとめられて現実に重宝しているのですが、今回の話のポイントは最初のwindowのブロックのところです。

property ExHandler : load script file "MyHD:MyScripts:library:_mouseClick.scpt"

tell application "System Events"

tell process "GraphicConverter"
set frontmost to true
keystroke "m" using {command down, control down}

tell window "Convert & Modify"
set {_x, _y} to get position
ExHandler's mouseClick({_x + 200, _y + 370}, "left", 1, "", 0.1)
end tell

tell window "Batch"
set {_x, _y} to get position
ExHandler's mouseClick({_x + 400, _y + 70}, "left", 1, "", 1)
delay 1
keystroke "v" using command down
keystroke tab
keystroke "v" using command down
keystroke tab
set {_x, _y} to get position
ExHandler's mouseClick({_x + 600, _y + 125}, "left", 2, "", 4)
end tell

tell window "Save"
keystroke return
delay 1
click button "Replace" of sheet 1
end tell

tell window "Batch"
keystroke return
end tell

tell window "Convert & Modify"
set {_x, _y} to get position
ExHandler's mouseClick({_x + 10, _y + 5}, "left", 2, "", 1)
end tell

if not (exists (window "Convert & Modify")) then
display dialog "GC Scale finished " giving up after 1
end if

end tell
end tell

window "Convert & Modify"において、set {_x, _y} to get positionとはモニタ上でのwindowの最左上の座標取得です。
その座標から左200下370ピクセルの位置をクリックしていますが、モニタ上ではそこに目標の"〓 Edit Batches…"ボタンがあります。
実はUI Browserによって当該ボタンのUI element要素は、「button "〓 Edit Batches…" of window "Convert & Modify"」と取得できるのですが、なぜかclickコマンドが利きません。
これがGUI Scriptingができない場合なのかと隔靴掻痒していた中で、偶然mouseClickハンドラを思い出してピクセル値を実測、試してみたらたまたま救われた、それが本項の顛末。
スクリーンショットを撮って実測したり、クリックの秒数をあれこれ試したり、掛け値無しに泥縄です(苦笑)。
スクリプトの以下も同様で、全体作業が成功した時は嬉しさよりも疲れが前面に出ました。

以上2回が自分のGUI Scriptingに関しての実体験です。
GUI Scriptingは確かに最終手段と認識しました(笑)。
[applescript]
[mac]
[macintosh]

コメント(全0件)
コメントをする


記事を書く
powered by ASAHIネット