• 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: Sat, 6 Jan 2001 18:40:53 -0500

On Fri, 5 Jan 2001 00:52:55 -0500, "email@hidden" <email@hidden>

> repeat
> if (x is true)
> repeat
> delay 0.5
> end repeat
> end if
> if some property is false then return
> delay 3
> end repeat
>
> and I would add stuff inside either loop, like a property that I wanted
> to be able to set from the outside.

AppleScript isn't multi-threaded and doesn't handle Apple Events and also run at
the same time. You need to get rid of the repeat loop, and let the idle handler
do the looping for you. That way, when other scripts send Apple Events to your
script application, its applet shell will be able to receive the event and
dispatch it or handle it properly. (Note that telling a script application to
set one of its properties is just like sending a command to a "set" handler of
the script. Its just that the "set" handler is built in to the applet shell and
so doesn't appear in your script.)

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

Actually, if you want the script to quit, you won't need to reach in and set a
property. Just tell it to quit. The applet shell's "quit" handler will note
the command, and then when the idle handler (or run handler, or whatever your
script was up to) is done and returns to the applet shell, the shell will quit.

If you try to do the idle looping inside your own repeat loop, your script never
returns control to the applet shell, and it can't do anything for you.

> But I am still an interested scripter. Can I force a script closed from
> another script? I tried whatever ways I could think of to change a
> property from outside, but maybe I don't understand scope in applescript..

You can't force a script closed, but if your script lets the applet shell run,
you can tell it to quit and it will do it.

You can set properties of a script as well, but again, its the applet shell that
handles the "set" message, and the script won't handle the message unless the
applet shell gets to run. And that means the script's routines need to return,
rather than busy-waiting.

--
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: Re: Email from FM using Outlook
  • Next by Date: Re: Problems scripting the Finder with system
  • Previous by thread: Re: quitting an applet
  • Next by thread: Re: quitting an applet
  • Index(es):
    • Date
    • Thread