I’d need more information before I could really suggest something more specific, but here is an example launchd plist which is going to keep a specific app (BBEdit) running all of the time, no matter what, from the time that I log in to my Mac until the time I log out.
To those who don’t speak launchd – what the above does it tells launchd to run the program
/usr/bin/open -W -a BBEdit
and if that process quits, for whatever reason (either because it crashed or the user manually quit the app), it’s going to re-launch BBEdit. This is going to start when the user logs in and stop only when the user logs out.
The command open -W tells launchd to “wait” until the program (in this case, BBEdit) quits. The -a BBEdit tells open which app to wait for.
I’ve run this before and I’ve never encountered a situation where it did not work unless there was a problem with the application itself.
However, if you wanted to make absolutely sure that BBEdit was always running on your computer, and get notified if it is not, then you could use something like:
pgrep -iq BBEdit
which should tell you if BBEdit is running and what the PID (Process ID) is.
If I was doing this, I would make a shell script that runs every minute or so, and looks like this:
# if BBEdit is running, this program will immediately exit with no output.
pgrep -iq BBEdit && exit 0
echo "BBEdit is NOT running!"
Of course if you aren’t there to see the echo command, you’ll need some way to alert yourself. I use
I use https://healthchecks.io for my monitoring a bunch of systems and processes, including backup systems and web servers.
Recently it detected that the Keyboard Maestro Remote trigger server was not always responding reliably, which turned out to be caused by limits on the number of connections the server could handle (Keyboard Maestro’s user based continues to grow). This was relatively easily solved, but without the monitoring I would not have known it was occasionally failing.
It may or may not meet your needs, but I highly recommend it.
Alongside this is Lingon X for running servers - much easier than editing XML and dealing with launchd manually.
Sorry it took me a while to respond to this, but what I mean by ‘fails in a way launchd cannot recover’ is simply this:
Launchd will not run a broken script. There are cases where I have a script that was running, but breaks either due to a change I made to the way it runs, or an external dependency. In these cases, I need to be notified.