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…

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)

Hi dewshi,

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

good luck,
kel

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…



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???)…

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