1

I'm working on a cross platform app that doesn't use NIB files and trying to figure out how to create the standard OS X "Services" menu (a submenu of the application menu in most applications).

Looking at the nib file for standard Cocoa app, the services menu is defined like this:

<menuItem title="Services" id="NMo-om-nkz">
    <modifierMask key="keyEquivalentModifierMask"/>
    <menu key="submenu" title="Services" systemMenu="services" id="hz9-B4-Xy5"/>
</menuItem>

Obviously the bit that makes it work is systemMenu="services" but I can't see how to programmitically create a NSMenu item like this - there's no "systemMenu" property on NSMenu.

What magic is happening here?

3

You find the Services menu on NSApplication.

-[NSApplication servicesMenu]

See documentation.

1
3

For future reference, based on @catlan's answer here's some code...

// Create the services menu
NSApp.servicesMenu = [[NSMenu alloc] init];

// Create menu item for it
NSMenuItem* servicesItem = [[NSMenuItem alloc] init];
servicesItem.title = @"Services";
servicesItem.submenu = NSApp.servicesMenu;

// Add it to the app menu
NSMenu* appMenu = [[NSApp mainMenu] itemAtIndex:0].submenu;
[appMenu addItem:servicesItem];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.