/ Published in: Objective C
Programmatically add a menu item
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Beware: the keyEquivalent must be lowercase in order not to have the shift modifier NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:@"Action" action:@selector(menuItemAction:) keyEquivalent:@"r"]; [menuItem setTarget:self]; [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask | NSAlternateKeyMask]; // Add the menu item at the end of menu whose index is 1 (most probably the File menu) [[[[NSApp mainMenu] itemAtIndex:1] submenu] addItem:menuItem];