change menu text with modifier key

From other posts I learned how to detect modifier keys. For now, I use rdelmar’s simple way to quit my application from the menu with or without a confirmation dialog, depending on the Alt-key being pressed when I choose the menu item:


    on stopErmee_(sender) -- triggered from menu item
        set modKey to NSEvent's modifierFlags()
        if modKey =2^19 then tell current application to quit
        set theAnswer to button returned of (display dialog "Stoppen?" buttons {"Ja", "Nee"} with title "Muse" with icon caution)
        if theAnswer is "Ja" then tell current application to quit
    end stopErmee_

This works ok, but now I would like the menu text to change upon pressing Alt. Like it does in Real Programs! How do I go about that? (The menu is the only UI, the app is entirely controlled from a menulet).

Model: iMac
AppleScript: Xcode 4.5
Browser: Safari 536.25
Operating System: Mac OS X (10.8)

Have a look at NSMenuItem’s setAlternate: method, which you can also set in the UI. If that’s not enough, you need to make a delegate of the menu and use something like menu:updateItem:atIndex:shouldCancel:.

Thanks, that works!

Good. And the Borgen DVD has been ordered… :slight_smile: