Check for Application Close

Does anyone know of a better way to check the close of an application. I have a way I am using currently, but it requires a repeat loop to continue and it takes up enough resources to be noticed during what I am doing. If someone knows of a way that would be extremely efficient, I would be greatly appreciative. Thank you.


repeat
   delay 30 --Ideally more frequest than this, but remaining low on resource usage   
   tell application "System Events"
       if not (exists process "Whatever") then
           activate application "Whatever Else"
           exit repeat
       else
           
       end if
   end tell
end repeat

I’m not sure what you’re trying to achieve here, CJICantLie. Is this meant to be part of a larger script, or do you just want something running in the background that keeps a permanent watch on the existence of your application? If it’s the latter, you could use a stay-open script with an ‘idle’ handler:

on idle
	tell application "System Events" to set appClosed to not (exists process "Whatever")
	if (appClosed) then tell application "Whatever Else" to activate

	return 30 -- number of seconds to next check
end idle

If you save this as a stay-open application and run it, Mac OS itself will call the idle handler every 30 seconds, or whatever other interval you set as the value of the return.

Obviously, even if the script activates application “Whatever Else”, application “Whatever” will still not be there at the next check. :confused:

It is actually part of a larger script. I have set a script to close just about every program on my computer for WOW to run most efficiently. This bit of script at the end is to reactivate those programs that were closed, when WOW is exited. I have found that on average, my framerate in the game with those applications in the background running is about 10-12 fps, 2-4 fps in large cities. When I close all these applications(Finder, Safari, Adium, Dashboard, and Mail) while starting WOW, I get about 24-26 fps, 15-17fps in City. Much better framerate. At least tolerable. However, I would like it to open up those application right after exiting WOW, but everytime the repeat loop goes again for the check, my framerate drops significantly for a few seconds and comes back up to the tolerable range, but in the middle of combat, that is a long time and hinders the ability to play. I have instead decided to just make a script that I click on after I exit WOW, so that I have no need for a loop. I was just seeing if I could still include a check in the initial script without some kind of repeat loop or at least something that takes less processor time. This is my first time working with applescript and did not realize that a script was so processor intensive. I would not have thought so, being such small files and such simple things. If anyone has a suggestion I will make use of it, until then I will just use a seperate script. Thank you.