All AboutにAppleScriptの構造を上手に調べるという記事がありました。
AppleScriptがアプリケーションと連携して、そのオブジェクトを操作することは周知の通りですが、AppleScriptはアプリケーションのメニューをクリックするということまでやってのけます。
ただ、このメニューアイテムを直感的に記述することは、なかなかできません。
そのため、All AboutではUI elementsをディスプレイさせながらコーディングをしていく手法を紹介しています。
この方法も便利だと思いますが、もっと面白いスクリプトを見つけました。
AppleMailingListの記事です。
コードの末尾のtell application "Script Editor"でスクリプトを作成している部分も興味深いですね。
to chooseItem(i, l)
set c to choose from list l with prompt "Choose a " & i & ":"
if c is false then error number -128
c's item 1
end chooseItem
tell application "System Events"
set p to my chooseItem("process", name of processes whose visible is true)
tell process p to tell menu bar 1
tell menus to set m to my chooseItem(p & " menu", name)
tell menu m to tell menu items to set i to my chooseItem(p & " menu item", name)
end tell
end tell
tell application "Script Editor" to make new document at end with properties {contents:"tell application \"" & p & "\" to activate" & return & return & "tell application \"System Events\"" & return & "repeat until \"" & p & "\" is in name of processes" & return & "end repeat" & return & "tell process \"" & p & "\" to pick menu item \"" & i & "\" of menu \"" & m & "\" of menu bar 1" & return & "end tell" & return}