Creating and Using a Second Menu Item

Hey there,

So I’m creating an NSStatusItem for my application and have all the code in place that creates the Status Item, and wires up a menu item on the main menu to it.

This works fine, and I can attach the ‘choose menu item’ handler to this menu item and receive those events. All is good in the world!

The only problem with this is that the menu item being used by the Status Item also shows up in the application’s main menu. So I created a second menu item in the nib, gave it the right name, and put some options on it, again attached to ‘choose menu item’, and wired up to the NSStatusItem.

This works fine, though I have to reference it as

set status_menu to item "nameOfStandAloneMenuItem"

whereas before I would be:

set status_menu to menu item "nameOfMainMenuItem"

It doesn’t let me reference it as ‘menu item’ for whatever reason. ( Just FYI status_menu here is then passed in a call method to the objective-c class that handles the NSStatusItem. )

This then means that the ‘on choose menu item theObject’ handler doesn’t work properly, as it expects ‘theObject’ to be a menu item, not just an item. At least that’s how I’m figuring it out. So this stops me being able to handle when menu items are chosen from the status item’s drop down.

Having searched these forums it seems there are a lot of problems people are having with using a second menu item inside their nib - I’m hoping someone will be able to shed some light on this showstopper!

I wonder if creating a seperate nib is the way to go, and use the mainmenu inside the second nib. Not sure if this would conflict with the first main menu from the original nib or even if it would fix the choose menu item handler anyway, but I may give it a try.

Here’s an example of how you need to do it…
http://www.jonn8.com/html/MenuApp.html

Hey there,

Thanks for the suggestion.

Sadly thats one of the projects I’ve already looked at for help. The problem with it is that the menu shows up in two places - once attached to the NSStatusItem and again as one of the usual menu options and application gets, such as File, Edit, except this one is called ‘Status_Menu’.

What I want to do is have the menu for the StatusItem stored somewhere else (like a different nib) so that it won’t show up on the application’s menubar as well.

Thanks!
Ryan

OK, I understand your problem now. In that example the application is hidden and only shows the status menu, not the application menu too.

Here’s another idea you can try. I notice you tried just putting an NSMenu in the nib and that didn’t allow you to hook up the menu items. Other things have menus which might work. Try a popup button. Here’s what I would try. I would add another window to my main nib. I would set it so it wasn’t visible at launch. Use this “invisible” window to add a popup button with a menu… and use that menu as the menu for the status item. The popup button will be on a hidden window and thus you’ll never see it in your main application.

It might work!

Aha yes - then I should be able to reference it as ‘menu item’ and subsequently the ‘on choode menu item theObject’ will hopefully be satisifed that ‘theObject’ does indeed contain a menu item!

I’ll give that a try and post my results :slight_smile: Thanks.