I solved the problem like this:
In my AppController’s init method I added an observer to receive an
NSApplicationWillFinishLaunchingNotification
to remove the extra menu items. This won’t work. Xcode adds the extra items after this. You have to add a selector that will be notified by the
NSApplicationDidFinishLaunchingNotification.
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver: self selector: @selector(handleAppLaunched:) name: @"NSApplicationDidFinishLaunchingNotification" object: nil];
The method to remove the extra menus looks like this:
- (void) handleAppLaunched: (NSNotification *) note
{
NSMenu* edit = [[[[NSApplication sharedApplication] mainMenu] itemWithTitle: @"Edit"] submenu];
while( [[[edit itemAtIndex: [edit numberOfItems] - 1] title] compare: @"Paste" ] != 0) //-1 for zero indexing
[edit removeItemAtIndex: [edit numberOfItems] -1]; //decrements the number of Items
}
The undocumented API for removing these with the user defaults is a cleaner way to do this.
It’s pretty ridiculous that there are un-documented APIs and that there is no straight forward way to do this, like a build setting or object method, since this is something you would want to do for a lot of applications.