これは GUI スクリプトと呼ばれます。UI 要素への参照を識別する必要があります。
GUI スクリプトは、システムのバージョンに大きく依存します。更新によって UI 構造が変更されると、スクリプトは中断します。
これにより、サウンドポップアップメニューでサウンド「ポップコーン」が選択されます。エルキャピタン用です。10.11 より前のシステムでは、UI 要素が異なる可能性があり、プロセス名が「iChat」である可能性があります。
tell application "System Events"
tell process "Messages"
set frontmost to true
if not (exists (1st window whose value of attribute "AXIdentifier" is "MessagesPreferencesWindow")) then
keystroke "," using command down
repeat until exists (1st window whose value of attribute "AXIdentifier" is "MessagesPreferencesWindow")
delay 0.1
end repeat
end if
tell (1st window whose value of attribute "AXIdentifier" is "MessagesPreferencesWindow")
tell pop up button 4 of group 1
click
delay 0.2
click menu item "Popcorn" of menu 1
end tell
end tell
end tell
end tell