Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close App A when App B closes: Mac OS X 10.7.3

Say I have two applications running; App A and App B. What would be the easiest way (or indeed is there anyway) to get App B to close automatically when App A is closed? Note that neither of the apps in question have been developed by me and so I have no control over their internal behaviour.

I am open to any suggestions including those that entail the use of Applescript, Automator, Terminal commands and BASH scripting. I would even consider developing a lightweight Mac OS X application to achieve this.

like image 776
Barjavel Avatar asked Dec 17 '22 03:12

Barjavel


1 Answers

If you don't need B to exit immediately - if it's OK to wait a few seconds - then you could schedule a periodic background task (using cron or even just iCal) that does something like this:

if not exists (processes where name is A)
   tell application B to quit
end if

Another option, if you want an immediate response, would be to wrap App A in a script that launches it, waits for it to terminate, and then terminates B (osascript -e "tell application B to quit"). Then you could just always use that script to launch A.

You could even insert the script into the application bundle so that double-clicking runs your script. You would do this by doing "show package contents" on the application, replacing the <CFBundleExecutable> in <app>\Contents\info.plist with your script name, and dropping that script into <app>\Contents\MacOS. Then have the script just run the executable that is already there.

like image 88
Russell Zahniser Avatar answered Dec 18 '22 16:12

Russell Zahniser