check to see if application alreay running

I’ve had fairly extensive experience with AppleScript, but I’ve been away from it for a while. Basically, I want to know if you can chek to see if an application is already running. I’m going to have a script that will do a bunch of processing and then call itself again. So, it’ll be constantly running, UNLESS there’s an error in the processing(which in my script isn’t that uncommon). So, I want this other script to periodically see if this script is running, and if it’s not, start it up again. Does that make sense? Thank you very much if you can help in any way.

Browser: Safari 312
Operating System: Mac OS X (10.3.9)

Ok, I just thought of something. If I simpy use the “activate” command, it’ll open the script app if it’s not already open, right? And if it is already open, it’ll simply switch to it, right? Could someone please either deny or confirm this? If this is tru, I think my problem is solved.

Hi,

AppeScript applications are different from regular apps. You need to use the 'launch command:

tell app “ScriptAppName”
launch
activate
end tell

gl,

tell application "System Events" to get name of every process
set ProcessList to result
if ProcessList does not contain "Safari" then
	tell application "Safari" to activate
end if

Hi,

So, because of the mistake you need to use ‘launch’ and ‘run’.

tell app “ScriptAppName”
launch
run
end tell

According to AppleScriptLanguageGuide.pdf, there is an implicit run command sent to the script app in the tell atatement. When you send it another run, then it locks up waiting for the reply. launch just opens it without running.

gl,

Thank you very much for the info. I’ll start plugging away at it and ask more questions as they come

okay, here’s a question. When you call an applescript application from another applescript, does the original applescript wait for the applescrpt that you called to finish before going on? I’ve thought about having a series of applescripts that call each other that get evrything that needs to be. However, it’s looking like this will present a problem. I guess I could have one humongous applescript that did everything, but that would make things really messy. I want to keep things seperated if possible. Please shed any light if you can. Thanks.

The only caveat I would add to this is that the first line:

tell application "System Events" to get name of every process

should be run first with the target application running to see what System Events calls it. Firefox, for example, returns “firefox-bin”, so the test looks like this:

if ProcessList does not contain "firefox-bin" then
	tell application "Firefox" to activate

Thank you everyone for your input, but it looks like I might not even have to worry about this. I fixed some of the problems with QuicKeys. At the end of each script I just call a QK shortcut that calls the next script. That way the first script closes and the 2nd one runs. I did everything I could to break the one script that usually breaks down, but it still worked. So, if I can get this looping thing working, I might not even have a problem. I’ll have to test it more, but it seems like it’ll work most of the time now. Hopefully it’ll error out rare enough so that if I see that the scripts aren’t looping, I can just start it up again.