Inspired from the answer of gs, here is what I have added to my code. I'm calling setupBundleNameInMenuBar
in AppDelegate's awakeFromNib
.
This code will replace all occurrence of "NewApplication" with the application name.
- (void)setupBundleNameInMenuBar {
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleNameKey];
if (appName == nil) appName = [[NSProcessInfo processInfo] processName];
NSMenu *menuBar = [NSApp mainMenu];
for (NSMenuItem *menuItem in [menuBar itemArray])
[self replaceTitlePlaceholderInMenuItem: menuItem withString: appName];
}
- (void)replaceTitlePlaceholderInMenuItem:(NSMenuItem *)root withString:(NSString *)appName {
root.title = [root.title stringByReplacingOccurrencesOfString: @"NewApplication"
withString: appName];
NSArray *submenuItems = [root.submenu itemArray];
for (NSMenuItem *menuItem in submenuItems)
[self replaceTitlePlaceholderInMenuItem: menuItem withString: appName];
}