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
source share