• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Quitting from an idle handler
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Quitting from an idle handler


  • Subject: Re: Quitting from an idle handler
  • From: Gil Dawson <email@hidden>
  • Date: Sun, 7 Aug 2005 13:50:24 -0700

Thanks for the suggestion.

After tinkering with it a bit I realize that I had misdiagnosed my problem. My problem is that I have not figured out how to quit a stay-open script.

Consider the following saved as a stay-open application:

FatalError("Please stop.")

on FatalError(msg)
	display dialog "Fatal Error:" & msg buttons "OK" with icon stop
	tell me to quit
	error "He didn't quit. "
end FatalError

I am using Smile 2.6.9 and MacOS 10.4.2. When launched on my machine by double-clicking its icon, this little script displays the "Fatal error: "Please stop." dialog, then another dialog with "He didn't quit". After that it does nothing, but remains an active process with an icon in my dock.

I don't want it to remain an active process.  I want it to quit.

How can I get it to quit?

--Gil


At 8:27 AM -0400 8/7/05, J. Stewart wrote:
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

_______________________________________________ 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
  • Follow-Ups:
    • Re: Quitting from an idle handler
      • From: "J. Stewart" <email@hidden>
References: 
 >Re: Quitting from an idle handler (From: "J. Stewart" <email@hidden>)

  • Prev by Date: Re: Finder Info to get real audio media source URL
  • Next by Date: Re: Script Menu in Tiger: non-persistent property bug?
  • Previous by thread: Re: Quitting from an idle handler
  • Next by thread: Re: Quitting from an idle handler
  • Index(es):
    • Date
    • Thread