Disable Main Menu Items

How would you disable all the items in the main menu at the top of the screen and how would you disable specific ones?

Turn off auto-enable in the menus, and then turn off enabled in the menu items themselves – you can do it in Interface Builder, or programmatically with setEnabled_ and setAutoenablesItems_.

Why doesn’t Apple just default it off?

Why should they?

How would you disable the dock menu because I can’t get it to work for that. But it did work for the main menu.

Are you trying to hide the application’s Dock icon? Or disable its default menu (Quit, Hide, Show in Finder, Hide)? Or do you have a custom Dock menu that you want hidden under certain circumstances, but not others?

I’m not sure its possible to have a Dock icon, but no menu… I guess you’re trying to disable specific menu items there… which ones?

If you don’t want a Dock icon at all, that’s easy enough.Go to your appName-info.plist, add a row and scroll through the list of names to “Application is agent(UIElement)” and hit enter twice, then check the box next to it.

Actually I added a custom menu to the dock and I want to disable that menu not the quit, hide, options, etc. and I want those actions to still be there but disable all the custom ones I added.

Under what circumstances do you want them disabled? Only when the application is inactive?

If Shane’s solution doesn’t work for you, maybe you can do something like create two dock menus with the same actions listed. But for the menu where you want them disabled, just never connect them to their respective handlers.

So then you’d have two menus, one enabled (because its menu items are connected to actions), and one not.

Then in your AppDelegate you need to have

The do stuff part is the only thing I don’t know, but it would be a command that would switch your DockMenu from the enabled menu to the disabled menu, and vice-versa. “applicationWillBecomeActive_” will run its method just before you application is activated (i.e. you click on its dock icon, or switch to it with command-tab). “appicationDidResignActive” will run just after you’ve switched to a different application.

I’m not sure what it is benefitting?

It’s a logical default. For example, it means things like Copy isn’t enabled if there’s nothing selected. Surely it would be odd to default the other way around.

Ahhh OK, is customise toolbar in View menu disabled when toolbar is hidden? If so I have some work to do.

Because it’s more comfortable for programmers.

¢ Each menu item which doesn’t respond to a selector is automatically disabled.
¢ The en-/disable state can be controlled dynamically with bindings and the method

-(BOOL)validateMenuItem:(NSMenuItem*)theMenuItem

This is much more efficient than en-/disabling menu items programmatically