There are two things to consider here: the script and the built-in, stay-open application that’s running it.
If you click the ‘Cancel’ in the ‘choose folder’ dialog, a “User canceled” error is generated which immediately stops the execution of the script. (If there were any commands after ‘choose folder’ in the ‘run’ handler, they wouldn’t be carried out.) However, the script application stays open (because it’s a stay-open application) and it immediately gets a signal to execute the first run of the script’s ‘idle’ handler.
The ‘quit’ command is aimed at the application, not the script. The application gets the command, but doesn’t act on it until it’s finished what it’s doing, ie. running the ‘idle’ handler. Once that’s out of the way, the application quits. (Actually, I think it quits before doing anything else the next time it gets the signal to execute the ‘idle’ handler.)
The only way I know to stop and quit a stay-open script immediately is to issue a ‘quit’ command and “User canceled” error in quick succession.
set a to ""
set a to choose folder
say "Hello" -- Not executed if the "Cancel" button's clicked.
if a is "" then
quit -- Quit when the script finishes,
error number -128 -- Stop the script now.
display dialog a
I assume you are talking about the dialogue with the name of the file/folder and not the choose one.
I thought that was odd that they wanted that to pop up all the time. I put it down to it being a test.
By the way your app does nothing my app does not do.
If I click cancel on the dialogue with the name of the file/folder it pops up again after the 5 second return in the idle handler.