Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jessica Lares

macrumors G3
Original poster
Oct 31, 2009
9,612
1,056
Near Dallas, Texas, USA
Can anyone recommend a tutorial for making a Menulet? There are loads all over Google, however, many of them are from years back and while they're all sorta similar, I'm running into problems because some code has been deprecated since then.
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,563
6,062
I have written menulets so I may be able to help. What specific code are you having issues with?

(Don't message it to me. Post it here. Just saying this premptively because when someone hears "I can help" online, they often try personal communication.)
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,563
6,062
Of course...

Well in this case I'm actually having more trouble with interface builder. I can't connect the delegate to the menu. I can do the Window though.

Hm. Personally, I just make the entire menu / menu UI in code. Making menus with icons, text, actions, and submenus in code is pretty trivial.

For Battery Status, I had a category on NSMenu that made adding that kind of stuff even more trivial. Here's some of the methods from it that I'll probably reuse in future projects (Battery Status supports pretty old Macs, thus why I have calls to release in here instead of just relying on ARC):

Code:
- (void)addSeparatorItem
{
    [self addItem:[NSMenuItem separatorItem]];
}

- (void)addItemWithTitle:(NSString *)title
{
    NSMenuItem *item;
    item = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:title
                                                                action:NULL
                                                         keyEquivalent:@""];
    [self addItem:item];
    [item release];
}

- (void)addItemWithTitle:(NSString *)title selector:(SEL)selector
{
    NSMenuItem *item;
    item = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:title
                                                                action:selector
                                                         keyEquivalent:@""];
    [self addItem:item];
    [item release];
}

- (void)addItemWithTitle:(NSString *)title image:(NSImage *)image
{
    NSMenuItem *item;
    item = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:title
                                                                action:NULL
                                                         keyEquivalent:@""];
    item.image = image;
    [self addItem:item];
    [item release];
}

- (void)addItemWithTitle:(NSString *)title indentationLevel:(NSInteger)indentationLevel
{
    NSMenuItem *item;
    item = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:title
                                                                action:NULL
                                                         keyEquivalent:@""];
    item.indentationLevel = indentationLevel;
    [self addItem:item];
    [item release];
}

I hope those help.
 

Jessica Lares

macrumors G3
Original poster
Oct 31, 2009
9,612
1,056
Near Dallas, Texas, USA
Hm. Personally, I just make the entire menu / menu UI in code. Making menus with icons, text, actions, and submenus in code is pretty trivial.

For Battery Status, I had a category on NSMenu that made adding that kind of stuff even more trivial. Here's some of the methods from it that I'll probably reuse in future projects (Battery Status supports pretty old Macs, thus why I have calls to release in here instead of just relying on ARC):

Code:
snip

I hope those help.

Thanks, that does help somewhat. I'll look into it later today.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.