objective-ccocoansmenunsmenuitemnspopupbutton

NSMenu programmatically select item


I'm writing a plugin for application - custom keyboard shortcut. I can traverse through its views. I need to open popup menu, select item in it, then open its submenu and select some item in submenu.

For now I'm only able to open top popup menu by sending performClick: to related NSPopUpButton element.

How can I programmatically select item in menu and open its submenu?

I've tried:


Solution

  • Use the NSMenu method - (void)performActionForItemAtIndex:(NSInteger)index

    NSUInteger idx = [[[menuItem menu] itemArray] indexOfObject:menuItem];
    [[menuItem menu] performActionForItemAtIndex:idx];