Is it possible to inspect the main application menu of some already running application and execute开发者_Python百科 commands from this menu? For example retrieve the whole main menu hierarchy of Safari and execute the File → New Tab command (by its name, not using the keyboard shortcut). I’m interested in an Objective-C solution.
One way to do this is using the Cocoa Accessibility API
For example,
NSAccessibilityPickAction Selects the object, such as a menu item
You could use Applescript This is not exactly calling the menus but for a well written program provides the same functionality and using a defined and discoverable API.
To send the events see Scripting Bridge
精彩评论