Monday, December 11, 2017

#1 2013-08-21 10:18:15 pm

dewshi
Member
Registered: 2009-08-09
Posts: 54

use button + ALT key

How do I set a button to perform a different action when the user holds down ALT?

So button changes title, different title = different action...

Applescript:

on clicked theObject
   
   --CODE/DECODE BUTTON ( button title set to "Decode" when holding down ALT)
   if title of theObject is "Code" then
       (*code routine here*)
   end if
   if title of theObject is "Decode" then
       (*decode routine here*)
   end if
   
end clicked

Browser: Safari 536.30.1
Operating System: Mac OS X (10.8)

Offline

 

#2 2013-08-22 01:18:39 am

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: use button + ALT key

Hi dewshi,

Interesting question. I used to know how to do this with an AppleScript app.

good luck,
kel


Os 10.10.3
Mbp

Offline

 

#3 2013-08-22 04:24:54 am

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2726
Website

Re: use button + ALT key

You could use the keyboard down and up handlers to change the title of the butten when the alt key is pressed. Unfortunately these handlers are bugged since Lion which results in errors.

edit: Some explanation would be nice right? The problem is that since Lion more events are send that necessary, the new events that are send are new and unsupported in AppleScript-Studio. Then you would wrap a try-error block around it right? Don't bother because the event is unknown and the error can't be catched with AppleScript. I've been struggling with a table view responding to the delete key for a long time already in Snow Leopard. There was a workaround but in Lion I was forced to recode the project into Objective-C.

Last edited by DJ Bazzie Wazzie (2013-08-22 05:43:26 am)

Offline

 

#4 2013-08-23 04:45:42 am

dewshi
Member
Registered: 2009-08-09
Posts: 54

Re: use button + ALT key

DJ Bazzie Wazzie wrote:

You could use the keyboard down and up handlers to change the title of the butten when the alt key is pressed. Unfortunately these handlers are bugged since Lion which results in errors.

edit: Some explanation would be nice right? The problem is that since Lion more events are send that necessary, the new events that are send are new and unsupported in AppleScript-Studio. Then you would wrap a try-error block around it right? Don't bother because the event is unknown and the error can't be catched with AppleScript. I've been struggling with a table view responding to the delete key for a long time already in Snow Leopard. There was a workaround but in Lion I was forced to recode the project into Objective-C.


Thanks for this info.
I'm not quite ready to up my game to Objective-C, so for the time being I'm stuck with the limitations of ASS (I'm on Mountain Lion with Xcode 3.2.6)

I did find a useful tip here: macscripter.net/viewtopic.php?pid=132090
and came up with this...

Applescript:



on clicked theObject

   --OPTION KEY
   if option key down of event 1 then
       set optionKey to true
   else
       set optionKey to false
   end if
   
   --DEBUG BUTTON
   if name of theObject is "debug" then
       if optionKey then
       --alternative action...
           display dialog "Option Key down"
       else
       --normal action...
           display dialog "Normal"
       end if
   end if

end clicked

The Debug button produces the desired actions... although there is no change of title to inform the User. A compromise would be to add a tooltip

I'm wondering if there's a way to employ a delegate for the Main Window to respond to the Option Key and change the title of the Debug button. This is a bit beyond my scope of understanding (I'm not completely sure what a delegate does???)...

Last edited by dewshi (2013-08-23 04:52:48 am)

Offline

 

#5 2013-08-23 05:12:31 am

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2726
Website

Re: use button + ALT key

Very nice and a great way of showing more ways to skin a cat. Thanks for sharing smile

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)