Wrong button chosen when dialog times out

Hi

Display dialog “Do you want to continue” buttons {“Sort”, “Quit”} default
button 1 giving up after 3

Something is wrong. It highlights the correct button but when the script
self-continues after 3 seconds it chooses the non default button. Strange.

Thanks for your insights…

Try this.

set dd to (display dialog "Do you want to continue?" buttons {"Sort", "Quit"} default button 1 giving up after 3)

if gave up of dd is true or button returned of dd is "Sort" then
	display dialog "Sort will begin now"
else
	if button returned of dd is "Quit" then
		display dialog "You chose to quit"
	end if
end if

– Rob

When using “giving up after”, if the dialog does “give up”, it doesn’t return the default button you set (in your case the “Sort” button). Instead it returns the button “”. However, the results are given the property {gave up:true}, so you need to catch this in your script. You might try this:


display dialog "xxxx" buttons {"Sort", "Quit"} default button 1 giving up after 3 
if gave up of the result is true then 
set returnedButton to "Sort" 
else 
set returnedButton to the button returned of the result 
end if 

Hope this helps.

That makes more sense. Is there an easier way to cancel (stop) a script if there is no user interaction?
In this script:
display dialog “The Folder has been named incorrectly.” buttons {“Cancel”} default button 1 giving up after 15

I expected that after 15s the script quits, intead it goes on, although the Cancel button is the default. How could I write this so the script quits after 15s?

Thanks again

I am sorry,
I think I was not clear in my previous post. What I meant is that even if I say

if gave up of the result is true then
set returnedButton to “Cancel”

the script does NOT quit (unlike if I CLICK the button labeled “Cancel”)

This might work. Error number -128 has the same effect as pressing the cancel button.

display dialog "The Folder has been named incorrectly." buttons {"Cancel"} default button 1 giving up after 15
if gave up of the result is true then error number -128
display dialog "still running" --< for demo only - it should never execute

– Rob