Re: Quitting from an idle handler
Re: Quitting from an idle handler
- Subject: Re: Quitting from an idle handler
- From: "J. Stewart" <email@hidden>
- Date: Sun, 7 Aug 2005 08:27:16 -0400
On 08/06/05 at -0700 Gil Dawson said this
>If my idle handler (waiting for another process to finish) detects an
>unrecoverable error, I want it to put up an error message then quit.
Seems reasonable.
>
>I was a little surprised to realize that I cannot use the "error"
>command to put up the error message because it will stop execution
>prior to the "tell me to quit" instruction, and the idle handler will
>simply execute again on the next cycle.
Sure you can. See my "try - on error" example below.
>
>Below is what I came up with. Is there a better way?
IMHO - yes
>
>BTW, are we fairly settled that coding an idle handler like this is
>less CPU-intensive than a delay command?
That would depend on exactly what you are trying to accomplish, they are meant for different things. Generally speaking, you would use "delay" in a script if you needed it to hesitate for some reason. An idle handler would be used in "stay open" scripts that you want to function periodically.
>
>MacOS 10.4.2, Smile 2.6.9
>
>--Gil
>
>display dialog "Run handler"
>
>on idle
> display dialog "Idle handler" buttons {"Error", "Cancel", "OK"}
> if button returned of result is "Error" then
> FatalError("Fatal error.")
> end if
> return 3
>end idle
>
>on FatalError(msg)
> display dialog msg buttons "OK" with icon stop
> tell me to quit
>end FatalError
I'd suggest looking at the built in AppleScript error handling routine. The discussion starts on page 261 of the ASLG (v1.3.7).
Here's a link to the ASLG pdf file.
<http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/AppleScriptLanguageGuide.pdf>
Here's an example try - on error handler:
try
error "This is a custom error!" number 501
on error errText number errNum
display alert (errNum as Unicode text) & ¬
": " message errText giving up after 5 as warning
display dialog "Your quit code goes here."
end try
JBS
--
Inside every older person is a younger person wondering "What happened?!"
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden