How to keep a Mac program running even if it has frozen (stalled) or crashed

I’ve written a script that monitors a particular app, ensuring that it keeps running, even if it’s frozen or has crashed.

I have posted it on the StackOverflow site:

Let me know if you have any improvement suggestions.