Mac OS X: Loading and Unloading with launchd

In Mac OS X you can use cron to schedule tasks but you can also use launchd.  To use launchd to load or unload an agent where you’ve setup a task use the launchctl command.  Here we will use launchctl to manually start a process given that we defined a plist called /Library/LaunchAgents/ (where program is maybe the name of some program you want to fire up):

launchctl load Library/LaunchAgents/

Your application should fire up now.  Do not quit it for ten seconds. Wait about 15, then quit it. Notice it start up again. This is because it is a launchAgent and will restart any time it is closed.  Now run:

launchctl unload Library/LaunchAgents/

Watch your program close.

One comment

  • January 9, 2012 - 1:59 am | Permalink

    Ok, here’s a fun follow up… once the job is loaded with a StartInterval, how can we ask Launchd to let us know when it plans on running the job next?

    I.E., how many seconds ago did that job with a StartInterval of 600 last run?

    I’ve asked this here as well:

  • Comments are closed.