What is this, anyway?

Launchd was designed at Apple as a replacement for init.d, crond, rc.d, etc. Launchd not only provides everything that cron does, it can do so with even more flexibility and power. The only downside is that the XML configuration files required by launchd are nowhere near as simple to write.

That's where this application comes in. It's a simple way to generate common cron-style launchd plist files for use on your own system.

Installing a plist

To install a plist to run as your user:

# Create a folder for for the plists, if it doesn't already exist
mkdir -p ~/Library/LaunchAgents

# Put your plist in this directory
cp ~/Downloads/launched.your_script.plist ~/Library/LaunchAgents

# And load it up with launchctl:
launchctl load -w ~/Library/LaunchAgents/launched.your_script.plist

If your plist needs to run as a different user, including root, you'll need to install it to the systemwide launch daemons folder instead:

# Put your plist in the system directory
sudo cp ~/Downloads/launched.your_script.plist /Library/LaunchDaemons

# And load it up with launchctl:
sudo launchctl load -w /Library/LaunchDaemons/launched.your_script.plist

When you generate a launchd plist with this application, there are also instructions and scripts for installation on the generated plist's page.

Uninstalling a plist

Uninstalling a plist is just as easy as installing it. For a user plist:

launchctl unload -w ~/Library/LaunchAgents/launched.your_script.plist

And for root,

sudo launchctl unload -w /Library/LaunchDaemons/launched.your_script.plist

Debugging

If your plist doesn't seem to be running correctly, you can debug it by looking at the logs in console.app. Fortunately, launchd prefixes any activity with the label defined in your plist. So, continuing with the above example, search for launched.your_script to find any log entries related to your job.

Isn't there a tool to make this easier?

Yes. brew install lunchy && lunchy --help

Privacy and Security

This application has no way of listing the plists that have been created so far, and each plist is identified by a unique identifier rather than an incrementing id to prevent enumeration. Still, you should ensure that you keep private data out of the plists if possible.

To prevent accidental or malicious changes, it's not possible to edit a plist. Instead, each new version of a plist has a different identifier.

Learn More

man launchd
man launchd.plist