dismiss dialog with just a keystroke

Here’s the script:


		set dd to ¬
			display dialog "Your Excel Spreadsheed has finished calculating." & return & return & ¬
				"Do you wish to save it?" default answer "" giving up after 120 with icon stop ¬
				buttons {"Yes", "No"} default button "No"
		
		set hit to character 1 of (text returned of dd)
		
		if (gave up of dd is true) then
			set response to "No"
		else if (hit = "n" or hit = "N") then
			set response to "No"
		else if (hit = "y" or hit = "Y") then
			set response to "Yes"
		else
			set response to button returned of dd
		end if

(1) even with a keystroke, I still have to press return for the keystroke to be detected, rather than dismissing the dialog with just the keystroke by itself
(2) given a solution to (1), how can I have the text block have zero width

This is not possible unless the answer will be typed in within the “giving up” period of time, then the giving up will be exectuted after the given time

Not at all.

PS: Of course you can do all these things in AppleScript Studio

If you don’t need to get text from the user, then don’t include the default answer parameter.

display dialog "Your Excel Spreadsheed has finished calculating." & return & return & ¬
	"Do you wish to save it?" giving up after 120 with icon stop ¬
	buttons {"Save", "Don't Save"} default button "Don't Save"
set {button returned:response, gave up:gaveUp} to result

If this script will only run on Mac OS X 10.4 (AppleScript 1.10) or later, and if it’s appropriate for your script, then you could you could use the cancel button parameter:

display dialog "Your Excel Spreadsheed has finished calculating." & return & return & ¬
	"Do you wish to save it?" giving up after 120 with icon stop ¬
	buttons {"Don't Save", "Save"} default button "Save" cancel button "Don't Save"
set {button returned:response, gave up:gaveUp} to result

This would allow you to press return for Save and escape or command+period for Don’t Save.

Bruce, I think, he wants to have the option to type some character with a “hidden” answer field.
This keystroke should dismiss the dialog immediately and return the character.

Precisely correct, Stefan