I've been trying to get AppleScript to produce a cleaner bit of menu bar information, but keep getting stuck as I can't figure out how to recurse on these menu bar objects using AppleScript. Retrieving the properties of an object works when I ask it directly (see marker A1), but not when I use it in a "function" (see marker A2). In order to get the property at A2 I seem to have to cast the variable to a type, but that doesn't work either because the type contains a space (see marker .
Maybe someone more familiar with AppleScript can tell me how to do this.
on run argv
tell application "System Events"
set _app to item 1 of (every process whose frontmost is true)
end tell
tell application "System Events"
tell _app
set menustuff to menu bar 1
--(A1) retrieving property here does work
--return menus of menustuff
return my recurseMenu(menustuff)
end tell
end tell
end run
on recurseMenu(menustuff)
--( casting doesn't work
--set castMenuStuff to menustuff as menu bar
--(A2) retrieving property without casting also doesn't work
return menus of menustuff
end recurseMenu
In any case, what it is I'm trying to do is this: recursively walk through the menus and menu items, record their title (e.g. "New file"), path (e.g. "File-->New file"), enabled state and shortcut (e.g. Command+N).
When recursing it would also become simple to add a depth constraint, which will avoid cases like ctwise and The_Ben mentioned in the case of Chrome.