Objective-C: get menu information from an external application

I am trying to write an additional application for Mac OS that displays a context menu containing the currently active application menu items when a user presses a hotkey. I can do the display of the context menu well, but I cannot get the currently active application menu items. [[[NSWorkspace sharedWorkspace] runningApplications] filteredArrayUsingPredicate:] now I am using [[[NSWorkspace sharedWorkspace] runningApplications] filteredArrayUsingPredicate:] to get the name of the active applications, but NSRunningApplication seems to contain a little bit of other information. Is there a way to get application menu information from an external application?

UPDATE:

Using the ScriptingBridge framework seems to work quite well if you're happy using AppleScript:

  SystemEventsApplication* sevApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.systemevents"]; SystemEventsProcess* proc = [[sevApp applicationProcesses] objectWithName:appName]; for (SystemEventsMenuBar* menuBar in proc.menuBars) { for (SystemEventsMenuBarItem* menuBaritem in menuBar.menuBarItems) { NSLog(@"%@", menuBaritem.name); } } 

prints a menu list available in the application menu bar. They didn’t find a way to get the context menu, so I won’t call it just the answer ...

This was also useful: http://robnapier.net/blog/scripting-bridge-265

+6
source share
1 answer

You can use AppleScript to simulate clicking on a menu item, as shown here , but I'm not sure if it is possible to dynamically capture the names of all menu items to use this method, which you need to be hardcoded in the application.

0
source

Source: https://habr.com/ru/post/920280/


All Articles