Logo download gratis adobe after efects cs3 profesional Adobe Illustrator CS4 download adobe reader freeware download buy Adobe Illustrator CS4 for Mac free adobe photoshop 7 brushes download download oem Adobe Fireworks CS4 adobe robohelp 7 downloadadobe player 8 download download Adobe Flex Builder 3 cheap download adobe photoshop elements 5 Adobe InCopy CS4 buy cheap unable to download adobe acrobat readerfree download trial version of adobe photoshop download oem Adobe InDesign CS4 manually download of adobe flash player 9adobe illustrator download freedownload adobe shockwave player buy Adobe InCopy CS4 for Mac premier adobe free downloadcrack adobe photoshop cs3 downloaddownload adobe acroadobe flex download download Adobe Dreamweaver CS4 for Mac adobe photoshop cs2 free download download adobe acrobat reader 6 0adobe imageready download adobe photo editor download cheap Adobe Flash CS4 for Mac buy cheap adobe reader download portableadobe acrobat pdr free trial download download adobe flash player 8 cheap Adobe eLearning Suite where free download adobe acrobatfree adobe palace script font downloadadobe dream weaver 8 downloadadobe pdf reader download download Adobe Flash CS4 adobe acrobat free download adobe photoshop download site adobe indesign cs3 free download buy Adobe Fireworks CS4 for Mac

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
            componentsSeparatedByString:@"NewApplication"]
            componentsJoinedByString:[[NSProcessInfo processInfo] processName]]];
      }
    }
  }

Maybe you’ll find a use for it somewhere.

posted by ganyard at 10:30 pm  

3 Comments »

  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. TrackBack URI

Leave a comment

Copyright © Bithaus