Re: "idle" has different effect in X vs 9?
Re: "idle" has different effect in X vs 9?
- Subject: Re: "idle" has different effect in X vs 9?
- From: Bill Cheeseman <email@hidden>
- Date: Thu, 08 May 2003 07:28:35 -0400
on 03-05-08 5:51 AM, Charles Arthur at email@hidden wrote:
>
property chooseapp : ""
>
>
on run
>
if chooseapp is "" then set chooseapp to choose application with
>
prompt "Where is Post Armor X?"
>
set nowquit to false
>
tell chooseapp to run -- start PostArmor
>
idle (nowquit) -- idle for 10 seconds to let PostArmor start
>
set nowquit to true
>
with timeout of 1000 seconds
>
tell application "Eudora"
>
set setting 1 to "Verdana"
>
set setting 260 to 1 -- 1=off | 0= on ; turns off
>
format=flowed
>
set setting 6820 to 8110
>
activate
>
end tell
>
end timeout
>
if nowquit is true then tell me to quit
>
end run
>
>
on idle (nowquit)
>
if nowquit is true then tell me to quit
>
return 10 -- wait for 10 seconds before exiting the idle loop.
>
end idle
The AppleScript 'idle' handler doesn't take a parameter. I gather your
script compiles, so presumably your 'idle' handler is being interpreted as a
private handler of your own. When called, your 'idle' handler returns the
integer value 10. It never causes your script to quit, because it is called
only once, at a point where nowquit is guaranteed to be false. Because it is
not a real 'idle' handler, it doesn't cause the AppleScript 'idle' handler
to fire every 10 seconds -- or ever. Your script apparently runs once and
then just sits there doing nothing (assuming it was saved "run only").
Even if you called the AppleScript 'idle' handler correctly, your script as
it is structured now would make no use of it because the logic is wrong.
Here's what's happening in your script: (1) You set 'nowquit' to false and
launch Post Armor X. (2) You call your private 'idle' handler. Since
'nowquit' was just set to false, the first line of your private 'idle'
handler does not cause the script to quit. Then your private 'idle' handler
returns the integer 10 to your 'run' handler, but you make no use of this
integer value. (3) You launch Eudora and set it up, setting 'nowquit' to
true in the process. (4) You test 'nowquit' and, since you just set it to
true, you cause the script to quit. That's the end of your script; it sits
there doing nothing until you Quit it from the Finder (assuming you saved it
as "run only").
Your script should behave the same way in Mac OS 9. Since you say it works
there, this indicates that on 9 Post Armor X gets itself running quickly
enough that Eudora works correctly with it -- simply because Post Armor X
was launched first. You could test this proposition by removing the call to
'idle (nowquit)' near the top of the script and running it on 9 -- I'll bet
it still works.
The reason your script doesn't work on X is presumably because Post Armor X
launches more slowly on X or in a different order, and it isn't ready once
Eudora is running. The launch process on X is very different from that on 9,
proceeding in parallel, so to speak. Your script sets them both to
launching, and which one finishes launching first is anybody's guess. Your
script, as written, plays no role in this, having finished its first (and
only) pass, probably before either target application is running.
To fix your 'idle' handler, remove the parameter from the handler
declaration and from the call to it in the 'run' handler. You don't really
need to call the 'idle' handler explicitly in your 'run' handler, either --
the system will call a real AppleScript 'idle' handler for you, if you
declare it, automatically as soon as the 'run' handler exits, then every 10
seconds thereafter.
The script still won't work, however, because it isn't structured to take
advantage of the fact that the AppleScript 'idle' handler will fire every 10
seconds until the script quits. To do it right, you basically want the
'idle' handler to test whether Post Armor X is running yet and, once it is
running, then launch Eudora. Here's a script written in pseudocode that
ought to work:
on run
launch Post Armor X
end run
on idle
test whether Post Armor X has finished launching
if so, launch Eudora and quit me
return 10
end idle
You could do this more simply without an 'idle' handler, using the 'delay'
command in a repeat loop, and then you wouldn't have to save the script as a
"run only" applet, either. Like so:
on run
launch Post Armor X
repeat
test whether Post Armor X has finished launching
if so, launch Eudora and quit me
delay 10
end repeat
end run
If you know exactly how long it takes Post Armor X to finish launching, you
don't even need the repeat loop. But this approach isn't recommended,
because you can never really be sure how long the launch process will take.
Like so:
on run
launch Post Armor X
delay 10 -- or however long you know it takes
launch Eudora
end run
The hard part is to devise a test to determine whether Post Armor X has
finished launching. One possibility, at least if it is scriptable, is to
send it a harmless AppleScript command and test whether it responds
appropriately. Another is to use the Finder's scriptability to test whether
its process exists yet -- but this can get a little tricky since the process
will exist before it has finished setting itself up. There are other tests,
much discussed in the archives.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.