checking for a running script with every process?

Is there a way for an AS Studio app to tell whether a script is running by name and/or path?

In trying to figure this out, I found out that the simple line:

tell application "System Events" to set theprocs to every process whose name contains "whatever"

will fail if another script is open with a display dialog up run from the script menu:
System Events got an error: Can’t get every process whose name contains “whatever”.

The “whatever” script, run from the script menu:


repeat with x from 1 to 10
	set thereply to button returned of (display dialog "TESTING")
	if thereply is "OK" then exit repeat
end repeat

Additionally, if the Whatever script’s dialog is up, XCode won’t compile!

Hi Wood,

Interesting post.

Compiled scripts run through the Script Menu is run by System Events, so it is busy. What might work is saving the Script Menu script as an application. By doing this, it displays its own dialog. The down side (or feature) is that the dialog script is now a process when run.

gl,

thanks, kel.

is there any other way to tell whether a script is being run, other than by system events? i know for example you can tell the Finder to get the name of processes.

what i’m ultimately trying to do is prevent an AS Studio application from running a script contained within its own package if that contained script is already running on a schedule by cron.

I have also determined that it is not possible for a script running independently but contained within an application bundle to pass any variable values (such as script_is_busy) back to an application. Please correct me if I’m wrong.

The only thing I can think of to do is to write an is_busy value to user defaults. But this means the AS Studio application has to read defaults repeatedly in an idle loop. Seems like a big slow down.

Thanks.

Hi Wood,

The scripts created by AS Studio are compiled scripts and not script applications. The scripts never become processes. They are run by your app.

Where are you running the script from? Some handler in the same script that contains the idle handler?

gl,

There are two scripts in question if you include the main application controller script (call it main.applescript). The second one, call it task.scpt, is contained in the Studio package. So they are both compiled scripts from what you are saying. “Main” loads and runs “task” in several places conditionally – on clicked, on chose menu item, on idle. However “task” is also run on a schedule by cron. I want “Main” to be aware of whether “task” is being run by cron. Particularly during the idle handler. As I said, I was thinking of having “task” write to the user defaults for the application. But then the application has to read the user defaults at each idle pass.

So, the solutions I can think of are in order of preference / presumed speed:

  1. “main” checks somehow whether “task” is running
  2. “task” passes a busy variable back to “main”
  3. “task” writes to user defaults of “main” and “main” read them on idle pass.

It seems neither 1 or 2 is possible. Please correct me if I’m wrong. Maybe a shell script? Surely the system at some level has to be aware there is a script running even if it’s under system events?

Or, Is there another option? Maybe the finder knows script file is open?

Thanks.

Hi Wood,

I’ve never found a way to know if a certain compiled script is running.

Maybe if you use a seperate script for the cron and just use a flag in your qpp to show that the script is runnining. I’m still not sure about with what app crontabs are run for osascript and was planning to test it later. It might just take a copy of the text. There might be a hack to get the status of the compiled script, but in that case, you might just as well use the user defaults.

If I think of somthing good I’ll write back.

gl,