Re: Monitoring processes
Re: Monitoring processes
- Subject: Re: Monitoring processes
- From: "Marc K. Myers" <email@hidden>
- Date: Mon, 22 Jan 2001 16:33:22 -0500
- Organization: [very little]
Stephen Gross wrote:
>
Date: Mon, 22 Jan 2001 10:24:25 -0500
>
From: "Stephen Gross" <email@hidden>
>
Organization: Stuart Country Day School
>
To: "email@hidden"
>
<email@hidden>
>
Subject: Monitoring processes
>
>
I have a script that sequentially executes a list of scripts. The
>
problem is getting it to wait until one script has finished before
>
starting the next one. Here's my code right now:
>
>
=====
>
repeat with CurrentScript in ScriptList
>
open CurrentScript
>
set NameOf to name of CurrentScript
>
set CurrentProcesses to list processes
>
repeat until NameOf is not in CurrentProcesses
>
set CurrentProcesses to list processes
>
end repeat
>
end repeat
>
=====
>
>
The problem is that my machine keeps bombing out, and I *think* it's
>
related to my use of "list processes". Does anyone know either (1) a
>
different way to wait for an applet to finish, or (b) a better way to
>
use "list processes"?
From the way you're capturing the name of CurrentScript I would guess
that this whole thing takes place inside a "tell" to the Finder. You
might find that "list processes" will work better if it's not directed
through the Finder. Setting up a repeat loop the way you've got it
wastes an incredible number of processing cycles. You'll probably find
that your called scripts run twice as fast without this script grabbing
all the cycles. To get around this, the most effective thing to do is
put your monitoring in an idle handler that checks back every five
seconds to see if the called script has completed. You could also use
the "delay" command in the loop as you've got it; not as good but easier
to implement.
global ScriptList, itemCntr, nameOf
on idle
if (list processes) contains nameOf then
return 5
end if
set itemCntr to itemCntr + 1
if itemCnter > length of ScriptList then
quit
return
end if
set CurrentScript to (contents of item itemCntr of ScriptList)
set nameOf to name of (info for CurrentScript)
open CurrentScript
return 5
end idle
Note: This is untested code written off the top of my head.
Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
[1/22/01 4:32:50 PM]