• 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 an applet
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: quitting an applet


  • Subject: Re: quitting an applet
  • From: email@hidden
  • Date: Thu, 11 Jan 2001 17:18:18 -0500

On Thu, 11 Jan 2001 10:53:48 -0500, "email@hidden" <email@hidden>
asked,
> >So, your script would look like this.
> >
> > on idle
> > -- do your stuff here
> > if some property is false then quit
> > return 1 -- time to wait for next idle loop
> > end idle
>
> thanks ..Does this mean that I write my script
>
> init stuff (that runs one time)
>
> on idle
> everything else
>
> end idle
>
> and I save this as a stay open or normal applet?

Exactly correct. Save it as stay-open. (Otherwise, as soon as the run handler
returns, the applet shell quits.)

But there is a fly in the ointment. What if someone _launches_ your script
application? This is particularly troublesome if you have a handler you are
calling from another script. For example,

on run
say "Run" -- Initialize
end run

on foo()
say "Foo" -- Do the work, assuming we've initialized
end foo

If you just call this with,

tell application "My App" to foo()

you get the sequence, "Run", "Foo". But if you launch the app first,

launch application "My App"
tell application "My App" to foo()

you just get the "Foo" call, without the run handler being invoked.

If you throw in an idle handler,

on idle
say "Idle"
end idle

The sequences are:

[tell application "My App" to foo()]
Run
Idle
Foo
[return to calling script]
Idle
Idle...

But with the launch first,

[launch application "My App"]
(nothing happens in the script. It loads and sits there.)
[tell application "My App" to foo()]
Foo
[return to calling script]
Idle
Idle...

One final trick is that if you get a property of such a script. The "get" is an
event like any other, but handled by the applet shell and not the script itself.
The result is that the idle handler is the first

[launch application "My App"]
(nothing happens)
[tell application "My App" to get P1]
[return to calling script]
Idle
Idle...

The problem is that the idle handler can never assume that any other handler had
ever run. If your might get called after a "launch", making sure things have
been initialized is tricky, requiring you to set a flag, and clear it on exit.
(Don't forget the "continue quit" statement. ;-) )

--
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


  • Prev by Date: Moving the files!!!!!!!!!!!!
  • Next by Date: Kill this canard once and for all
  • Previous by thread: Re: quitting an applet
  • Next by thread: Re: quitting an applet
  • Index(es):
    • Date
    • Thread