MacOS – Launchd/Launchctl – pre and post scripting

launchdmacoszsh

Is there any way with ld/lctrl to execute pre/post commands similar to systemd's ExecStartPre/ ExecStopPost?

Best Answer

No, there is no such functionality in launchd (as far as I am aware, and I consider myself pretty familiar with launchd).

The best site that I know of for launchd info is https://www.launchd.info which is maintained by the developer of LaunchControl which is my favorite, and I would argue also the best, tool for managing launchd on the Mac, although I do have to admit that Lingon is also excellent.

If I wanted to do something like that with launchd I would end up making a shell script of some kind to run the command before, then run the daemon, then run the commands after. Not nearly as satisfying, of course.