How can I check for a crashed app, and then restart it?

I use an app called "Weatherman" to get daily weather forecasts for a couple of cities. It is AppleScript-able so I can grab the weather forecasts as text and add them to my daily "Read my schedule" macro. The problem is, after some days of running just fine, Weatherman will eventually crash. It is easy for me to force-quit the app and relaunch, but I want to do it automatically as this is all running on an unattended Mac. Is there a way for me to determine that Weatherman is not responding, and then force-quit it, and then restart it?

If it's not to much of a hassle I suggest to quit and restart the app daily by setting a scheduled trigger.

-Neo

What happens if you setup a simple KM cron job to run say every 15 mins. The macro would just have a single statement of Activate Weatherman
Presumably if Weatherman is running then it will continue to run
if it is not then the activate statement should kick start it

Can you not leverage the lack of response from your AppleScript call? Totally untested, but something along the lines of:

try
	with timeout of 20 seconds
		tell application "Weatherman"
			-- do current scripty stuff here
		end tell
	end timeout
on error
	do shell script "killall Weatherman"
end try

Thanks for this. I have tried this and it works most of the time. But... if the app has already crashed, and needs a force-quit, then it doesn't work. I could of course schedule the trigger to go multiple times a day but it seems like there is probably a better way.

This is another great idea except that if the app is crashed, the "activate" won't bring it back to life. The app hasn't quit, it's frozen (in the "not responding" way that requires a force-quit).

I think that your "killall WeatherMan" line holds the answer for me. Combining all of the answers (thank you, all of you!) I can have a trigger that doesn't QUIT WeatherMan but instead does a "killall WeatherMan" and then re-launches. That should do it! I'm setting that up now. THANK YOU!

The problem of determining whether an application will terminate itself or not is called the halting problem. It is an unsolvable problem. You can read the Wikipedia page about it if you wish. Even macOS does not know if an application is permanently not responding or not.