Re: Script Applet rejects first handler call
Re: Script Applet rejects first handler call
- Subject: Re: Script Applet rejects first handler call
- From: Paul Skinner <email@hidden>
- Date: Tue, 31 Jul 2001 12:19:41 -0400
on 7/31/01 11:29 AM, email@hidden wrote:
>
Here's something annoying: When I call a handler in a script applet from
>
another script, I get an error on the first call.
>
>
-- "Test": saved as a stay-open Classic applet
>
on run
>
say "Run"
>
end run
>
>
on h()
>
say "Handler"
>
end h
>
>
I save that script, and call it with this one:
>
>
tell application "Test"
>
h()
>
end tell
>
>
If "Test" is running, everything works as expected. But if it isn't, I get
>
the
>
error "Can't continue h". The error number is -1708 (errAEEventNotHandled).
>
>
This is under OS 9.1 with CarbonLib 1.3.1, AppleScript 1.6, and Script Editor
>
1.6. It also occurs if the scripts are compiled with Smile or with Script
>
Editor 1.1.3. It doesn't occur if I boot into OS 8.6 and AppleScript 1.
>
>
I understand that I can avoid the error by precautionarily telling the server
>
script to run before invoking any of its handlers, but that's not the way
>
AppleScript is supposed to work. Also, I have some scripts that are called
>
from
>
ListSTAR, and these can not be guarded with a "run", since ListSTAR doesn't
>
have
>
a script itself, it just sends <<event s9evts9Lis>> events at the scripts.
>
>
Any thoughts on how to restore the normal behavior? Barring that, does anyone
>
know which version of AppleScript I should revert to to regain the old
>
behavior?
I see this as normal behavior. I had no idea that it ever worked
differently.
In my experience the Until the server script is run it can't server it's
handlers. The first call to the script server finds it inactive and causes
it to run. But the call is lost. I avoid the issue by calling a property of
the server script at the top of the script which wants to use the server
scripts handlers. If you wrap this call in a try within a repeat until loop
then the first call launches the server script and the subsequent calls fail
until the script server is initialized. Then it works. With your example you
could do something like...
set serversUp to false
repeat until serversUp is true
try
tell application "Test"
h()
end tell
set serversUp to true
end try
end repeat
-->speaks 'run','handler'
it required only two loops in this example. My script server may take
several loops to initialize due to size and getting system info etc. but it
always works.
--
"AppleScript is digital duct tape."
Paul Skinner