Wednesday, October 22, 2014

#1 2012-12-06 05:08:26 am

rpvermeulen
Member
From: Rotterdam, Netherlands
Registered: 2011-04-23
Posts: 23
Website

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:

Applescript:


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)


Rob Vermeulen
Rotterdam, The Netherlands

Filed under: Menu, modifier key

Offline

 

#2 2012-12-06 04:13:49 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3699

Re: change menu text with modifier key

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:.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2012-12-08 04:44:02 am

rpvermeulen
Member
From: Rotterdam, Netherlands
Registered: 2011-04-23
Posts: 23
Website

Re: change menu text with modifier key

Thanks, that works!


Rob Vermeulen
Rotterdam, The Netherlands

Offline

 

#4 2012-12-08 04:45:05 am

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3699

Re: change menu text with modifier key

rpvermeulen wrote:

Thanks, that works!

Good. And the Borgen DVD has been ordered... smile


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.040 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)