I have multiple dialogs in a script, when i press cancel, it only cancels the current set of script and then goes to the next. Is there a way to end it all upon cancel?
if button returned of result is “Cancel” then return
display dialog "test 1"
if button returned of result is "Cancel" then return
display dialog "test 2"
if button returned of result is "Cancel" then return
display dialog "test 3"
I think the function of the “Cancel” button is set but you can make other buttons and define what you want them to do. The following should work if you have saved your script as an application. Otherwise, you might have the button throw an error to bring the script to a halt.
display dialog "Whatever" buttons {"Quit", "OK"}
if button returned of the result = "Quit" then
tell me to quit
end if
That shouldn’t work Adam (check the log):
display dialog "test 1"
if button returned of result is "Cancel" then
log "???"
return
end if
display dialog "test 2"
if button returned of result is "Cancel" then
log "??????"
return
end if
display dialog "test 3"
Clicking a button labeled “Cancel” generates error# -128:
try
display dialog "test 1"
on error errorMsg number errorNum
if errorNum is -128 then
-- User canceled.
display dialog "test 2"
else
log ("Error (" & errorNum & "): " & errorMsg)
end if
end try
Bonedoc, you need to clarify your question. It would probably be best to post the script you’re having trouble with.
Odd, Bruce. When I use your first script above in the Script Editor the script stops at that point and my event log just says “User Cancelled”. If I let the first one go by, my log says:
That’s what it’s supposed to do. I don’t think I explained myself well. If you have a script like this.
display dialog "test 1"
if button returned of result is "Cancel" then return
.then that if statement will never be true, because AppleScript generates an error (number -128, for which the English message is “User canceled.”) when you click on a button called “Cancel” in a dialog. You won’t catch this error unless you use a try block.
Going slightly off topic (it sounds like the opposite of what bonedoc is looking for). You can use try blocks to catch a cancellation and “send” a user back to a previous dialog (e.g. Say Something).