I have a an application that runs in a UI user session in OSX (a mono app that runs in a terminal window, a command line program). Sometimes this mono app exits for whatever reason, and a shell script that runs every 2 minutes as launchd checks to see if ps ax | grep "mono"
only returns the grep command as the only mono process. If so, spawn a new terminal window and in that terminal window run the mono program again.
Anyway, sometimes this leaves a large number of terminal windows open. What I would like is either to append to this shell script or perhaps in Applescript which I can call in my mono app to close every terminal window not running a mono process. Can Applescript determine if a terminal window is running a certain program? Can shell determine that? If so, how?