2010-03-27T17:43:35+09:00

スクリプトメニューを表示させる AppleScript

スクリプトメニューを表示させる AppleScript とです。何らかのユーティリティに登録して、キーボードで実行してキーボードでメニュー項目を選べたら便利かなと思って。ちなみに、僕は DragThing に登録してショートカットキーを割り当てて使っています。

コンパイルには、ModuleLoaderGUIScriptingChecker をあらかじめ用意しておく必要があります。そういうめんどくさいことしたくない人は、こちらからダウンロードしてください。

こんな感じで ModuleLoader を使ってモジュール/ライブラリに依存したスクリプトをつくっても、実行時には ModuleLoader や使用したモジュール/ライブラリは必要ありません。こういうことができるのが AppleScript のいいところ。

property GUIScriptingChecker : module
property loader : boot (module loader) for me

on run
try
main()
on error msg number errno
if errno is not -128 then
activate
display alert msg message "Error Number : " & errno
end if
end try
end run

on main()
if not do() of GUIScriptingChecker then
return
end if
tell application "System Events"
tell application process "SystemUIServer"
tell menu bar 1
set a_list to menu bar items whose attribute "AXDescription"'s value is "AppleScript"
if (count a_list) < 1 then
activate
display alert "No script menu"
return
end if

tell item 1 of a_list
perform action "AXPress"
end tell
end tell
end tell
end tell
end main