Those stinkin’ NewApplication menu items.
I feel pretty bad.. it’s been a long time since I’ve posted. I had such good intentions about doing this regularly, didn’t quite keep that up. To allay my guilt, here’s something (I think is) useful.
Why can’t I just have some kind of substitution token for my App name in my menus? It would be so nice if this was just handled for you. Or even just use preprocessor macros. Or something so I don’t have to build things programmatically.
I’m working on a project which produces various targets, why would I want a separate MainMenu.nib for each target, when except for the App name they are the same (or at least nearly so).
So here’s what I did in my AppController’s AwakeFromNib:
NSEnumerator *menuEnumerator = [[[NSApp mainMenu] itemArray] objectEnumerator];
id menuItem;
while (menuItem = [menuEnumerator nextObject]) {
if ([menuItem hasSubmenu]) {
NSEnumerator *subMenuEnumerator = [[[menuItem submenu] itemArray] objectEnumerator];
id subMenuItem;
while (subMenuItem = [subMenuEnumerator nextObject]) {
NSString *menuTitle = [subMenuItem title];
[subMenuItem setTitle:[[menuTitle
componentsSeparatedByString:@”NewApplication”]
componentsJoinedByString:[[NSProcessInfo processInfo] processName]]];
}
}
}
Maybe you’ll find a use for it somewhere.
