How to use Launchd

Mac crontab command seems to be deprecated on Mac OS X, and the Apple documentation encourages you to use their “Mac launchd” facility.

launchd

launchd manages processes, both for the system as a whole and for individual users. The primary and preferred interface to launchd is via the launchctl(1) tool which (among other options) allows the user or administrator to load and unload jobs. Where possible, it is preferable for jobs to launch on demand based on criteria specified in their respective configuration files.

There are three main directories you can use with launchd:

  • /Library/LaunchDaemons Put your plist scripts in this folder if your job needs to run even when no users are logged in.

  • /Library/LaunchAgents Put your plist scripts in this folder if the job is only useful when users are logged in. (Note: I learned that this has the side-effect of your job being run as ‘root’ after a system reboot.)

  • ~/Library/LaunchAgents Put your plist files in this folder if the job is only useful when users are logged in. (When your plist configuration file is placed here, your job will be run under your username.)

Read More