Warning: include_once(/home/ganyard/bithaus.com/wp-content/plugins/lightbox-plugin.php): failed to open stream: Permission denied in /home/ganyard/bithaus.com/wp-settings.php on line 305

Warning: include_once(): Failed opening '/home/ganyard/bithaus.com/wp-content/plugins/lightbox-plugin.php' for inclusion (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/ganyard/bithaus.com/wp-settings.php on line 305
Those stinkin’ NewApplication menu items. – Bithaus

Thursday, January 18, 2007

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
            componentsJoinedByString:[[NSProcessInfo processInfo] processName]]];

Maybe you’ll find a use for it somewhere.

posted by ganyard at 10:30 pm  


  1. Very cool use of componentsSeparatedByString: never really though of using it that way!

    Comment by Rick Steele — January 22, 2007 @ 9:37 am

  2. Thanks.
    It just looked like the simplest way to do that, kinda harkens back to using text item delimiters in AppleScript.

    Comment by ganyard — January 22, 2007 @ 9:44 am

  3. Nice, I saw your post on the Cocoa Students list and now you have published the answer. I think this will come in handy even though I only have a single target (I tend to change the application’s name frequently). Thanks.

    Comment by Kyle Killion — January 26, 2007 @ 2:31 pm

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Copyright © Bithaus