Re: Script Applet rejects first handler call
Re: Script Applet rejects first handler call
- Subject: Re: Script Applet rejects first handler call
- From: email@hidden
- Date: Fri, 3 Aug 2001 15:38:14 -0400
On Fri, 3 Aug 2001 09:33:09 -0400, Deivy Petrescu <email@hidden>
commented,
At 7:06 PM -0400 8/1/01, email@hidden wrote:
>
A script saved as stay open is the same thing as a running script
>
while this script is running.
I did a quick experiment, and found out it things are a little more complicated
than I thought. Under AppleScript 1.5.5, here are some key observations I've
made.
1. The run handler can't be interrupted.
The following script was saved as a script application and run. I tried it as
both a stay-open and non-stay-open applet.
on run
repeat
play sound "Simple Click"
delay 2
end repeat
end run
on h()
play sound "Submarine"
end h
I called it from a one-line script in the Script Editor
tell application "pserver" to h()
The run handler cycles and clicks, the caller waits, and the handler h() never
runs. This happens whether the server script was already running, or whether it
runs implicitly because of the "tell" command.
2. If a script isn't stay-open, you get one handler call to it. A call to the
"run" handler counts as that one. So you have to make such a call like this:
tell application "pserver"
launch
h()
end tell
>
Whether you like this behaviour or not, it is not the point. It is
>
stated there in the guide as a behaviour of a script application and
>
any other application. The example uses SimpleText. If the
>
application is not running, whatever is the nature of the app, a
>
launch is recommended.
For both script applications and regular applications, the behaviors are the
same and well documented: if an application gets a "run" AppleEvent, it does the
same thing as if you were to double-click it. (In that case, the Finder sends a
"run" event.) Specifically, for the script application, it invokes its "run"
handler.
If you want the application to start, but not get a "run" event, you can
manually launch it. That is an option that you, the writer of the calling
script, can exercise, or not.
>
As for first in last out or first in first
>
out, this is also documented, as you pointed out, thus is not a bug.
>
I was not questioning if this is the best way to deal with all apps
>
or a different procedure should be adopted. As far as my reading is
>
concern, what you wrote and what Chris (Nebel) reported as bug, is
>
what I read in the guide as paths to avoid.
The last-in, first-out behavior is indeed documented, and that's how it works in
AppleScript 1.5.5. But in 1.6, the behavior is last-in, error message. That's
a bug.
>
If the error message is the problem, I would not call it a bug either.
>
As being a suggestion for a different approach I do understand your
>
point. However, reading your email many times ( may be I am slow) I
>
read the guide as telling you "don't do that!". And if launching
>
solves the problem, I think the guide proposes a solution as well.
The problem with launching as a workaround to the 1.6 bug is that it can't be
used for CGI scripts, for ListSTAR scripts, and for scripts applications that
use their run handler to initialize. Its probably trouble for Folder Actions as
well, if you want the folder action script to be an application. (Has anyone
tried this?)
--
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