Recently had an issue where an application / process I would leave running on my macbook overnight would crash and stop running. I needed a way to automatically restart the application / process if it wasn’t running, having a never ending spooling loop wouldn’t work (and is a nasty way to do it).
So I came up with the following AppleScript code.
Copy and paste into AppleScript Editor, make the changes you need, and save it as an “Application”. Remember to tick “Stay Open” when you save it. I’ve dropped, what i’ve called the “Heartbeat App” onto the dock and set it to start when the computer does.
repeat delay 60 set core_is_running to is_running("NAME OF PROCESS OR APPLICATION") if core_is_running is false then tell application "NAME OF PROCESS OR APPLICATION" to activate set core_is_running to is_running("NAME OF PROCESS OR APPLICATION") end if end repeat on is_running(appName) tell application "System Events" to (name of processes) contains appName end is_running
delay 60 is the time interval in seconds you’d like the heartbeat app to check for the application or process.
To find out the NAME OF PROCESS OR APPLICATION, simply run the application / process, then look under Process Name in Activity Monitor.
You could also adapt this to run an application / process every x amount of time if you so wished.