Making Applescript wait until a program is closed.

I have a program that is running off of a cron job which employs a perl script. The purpose of this script is to open a program, Vectorworks, and let it run some design scripts. Once perl has set up the environment, it calls osascript on an applescript which opens up VectorWorks and kicks off the design scripts. The thing that I need to have happen is I need applescript to wait until these design scripts are finished running and VectorWorks is closed before it returns. Thus also suspending the perl script. I have setup a fork call in perl and have the parent wait for the return of the applescript. The problem is once the VectorWorks program starts up, the applescript program terminates and returns prematurely. Anyone have any ideas on how to get around this?

In a hurry here - the dinner bell just rang! :wink:

If VectorWorks runs a series of AppleScript scripts in sequence, couldn’t you could add a return to the last script. If that works, you might need to lengthen the timeout on the script that starts VectorWorks.

Well what is happening is that VectorWorks is running a bunch of VectorScripts which are started by the Applescript. I need Applescript to hangout while these scripts complete before Applescript returns to the Perl script. Instead of just kicking the Vectorscripts off and then returning.

I am not familiar with VectorWorks so some questions may appear to be stupid. :stuck_out_tongue:

Is it possible to have VectorWorks create a signal at the end of its script run? For instance, if it could create a file with a unique name (complete, continue, whatever), the AppleScript script could go into a loop that perdiodically checks for the signal file’s existence and then proceed when the file is detected.

This is the route which I was thinking of taking. But I was hoping that there might be some sort of thread setup for applescript but I guess I can deal with a signal file. thanks for the input. I just get tired of jumping through hoops. :?

Am I correct in assuming that VW isn’t actually scriptable via AppleScript?

You say that you want to have the applescript wait till vectorworks is closed, right? If so couldn’t you just throw a repeat loop in there that checks to see if vectorworks is a current process? Either in the applescript or maybe via something like the command line ps when the control is handed back to the perl script.

-john

I already thought about this. Because VectorWorks is not started from the terminal it does not show up in the active process listing that you get from doing a PS.

Huh?

ps shows all processes, regardless of how they were started, or who started them.

Of course, you might need to add a few switches to get the full story (otherwise ps may only show your processes and not those owned by other users, or may truncate filenames, etc.)

Try:

ps -auxww

and you’ll see what I mean.

In any case, from an AppleScript perspective, System Events is your friend:

tell application "System Events"
  if (name of every application process) contains "VectorWorks" -- or whatever the app name is
   -- app is running
 else
   -- app already quit
 end if
end tell

Throw that in a repeat or an idle loop and you have what you want.

Thanks,
That was the information that I was looking for! I’m all set now.

Cheers!

Dave :lol: