Menu Magic

I was hunting around last night for the method behind this trick and I couldn’t really find it summarized in one place, so I thought I’d do it myself.

First, an example. Open the ‘Apple’ menu on your Mac. Now hold down the ‘alt/option’ key. See how some of the menu items change? Specifically, how ‘About This Mac’ changes to ‘System Profiler…’? This is all done with menu alternates, key equivalents, and key modifiers. But ‘About This Mac’ has no key equivalent. Wha happen?

Let’s start with menu alternates. A menu alternate is just a menu item marked as an ‘alternate’ to the menu item above it. This is just a tick box in Interface Builder, but that’s not all that is required.

The connection between the two is that they share a key equivalent, but the alternate has an extra modifier. So if you have one menu item with key modifiers ⌘ M and the one below it has ⇧⌘ M, then the first one will normally appear, but if you open the menu and hold down the shift key, the other menu item will appear, in place of the first.

So that’s the trick. Make the first menu normally, with no modifiers. Make the second menu item, make it an alternate, and give it a key equivalent of alt/option. The symbol will appear in the field in the inspector, but not on the menu itself.

Now you can try it out. Make sure that both menu items are connected to actions, and run your program. Open your menu. You should see the first item you made. Now press and hold the ‘alt/option’ key. Your second menu item should ‘magically’ replace the first one!

Leave a Reply

Your email address will not be published. Required fields are marked *