Re:Quitting an applet?
Re:Quitting an applet?
- Subject: Re:Quitting an applet?
- From: email@hidden
- Date: Mon, 4 Dec 2000 11:56:28 -0500
On Wed, 29 Nov 2000 15:46:58 -0500, Carl West <email@hidden> asked,
>
I want my script to quit if the user presses a particular button. It's
>
not happening.
>
>
Minimal case:
>
>
on run
>
quit
>
display dialog "it didn't quit"
>
end run
Its counterintuitive, but it makes sense to a nerd...
"Quit" doesn't mean "quit right now", it means "quit when you're done." (That
is, quit means "don't idle anymore and don't stay open.")
The "quit" command is handled by the script's applet shell, and is processed
like any other commend. Quit specifically sets a "told to quit" flag, and then
returns from the command to the caller. Then, when your run handler (or other
handler) returns, the applet shell gets control, and looks at the "told to quit"
flag and does what you want.
This is actually useful behavior, since a "quit" command can come from anywhere,
and not just internally. So, if one script tells another,
tell application "OtherScriptApp" to quit
Its nice to have OtherScriptApp not get the quit right in the middle of what it
is doing, but at the end of its processing cycle, when the run handler or other
called handler returns.
If you have "quit" in a script running under Script Editor, it can't quit.
There's no applet shell, instead the Script Editor itself gets the "quit"
message, and it can't quit because its busy running your script. Smile faces a
similar paradox, which it resolves by doing its normal "quit" functions, just
like you pressed command-Q. It asks if you want to save open files, and then
closes the documents, and then finds it has pulled the running script out from
under itself, and gives an error about "can't find window id 1".
So, how do you actually quit what you are doing? If you just want to terminate
the current handler, use "return". But what if you are in a subroutine, called
by the current handler, or maybe many levels deep into subroutines? You
probably want to return some sort of error code, and let the main handler decide
if stopping the script is justified. If you seriously want an "abort" that will
stop the script cold, then throw an error.
Some people suggest 'error number -128' which means "user cancelled". The
applet shell and Script Editor silently catch this error, and shut down the
script with no dialog box. (Other error numbers produce an error message from
the applet shell or the Script Editor.) However, Smile produces a "user
canceled" message. However, this may be acceptable if the user actually did,
somehow, cancel. Other "abort" situations are probably errors, and should be
treated as such, with an appropriate error number and descriptive text. 'error
("Can't find file " & filename) number -43' for example.
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden