iPipSubmit

← All tools

launchd plist maker

Fill in the job and pick when it runs. The plist and the commands update as you type, and nothing leaves this page.

launchd plist maker

Try an example:

What it does

On a Mac, the way to run something on a schedule, at login or all the time is launchd. You describe the job in a small XML file called a property list, put it in the right folder, and load it with launchctl. Apple still ships cron, but its own docs say it is deprecated in favor of launchd. This page writes that file for you. Type a label, the program and its arguments, and pick when it runs: every so many minutes, at a time of day, once a week, from a cron line you already have, at login, or all the time. You get the plist, a download, the Terminal commands to install and load it, and a few checks for the mistakes that stop a job from running. It all happens in your browser.

Where do launchd plist files go?

FolderWhat runs from it
~/Library/LaunchAgentsYour own agents. They run as you, while you are logged in. This is right for most personal jobs.
/Library/LaunchAgentsAgents for every user, loaded when each person logs in. Needs an admin password to add.
/Library/LaunchDaemonsDaemons. They run as root for the whole Mac, from start-up, even with nobody logged in.

Leave /System/Library alone: those are Apple's own jobs.

How do I load a launchd job?

The tool gives you the exact lines. For your own agent they look like this:

launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.yourname.backup.plist
launchctl kickstart -k gui/$(id -u)/com.yourname.backup
launchctl bootout gui/$(id -u)/com.yourname.backup

The first loads it, the second runs it right now so you can test it, and the third stops it and unloads it. launchctl load and unload still work, but Apple's man page lists them as legacy. Check the file first with plutil -lint, which says OK or names the line that is wrong. When a new job is added, recent versions of macOS show a Background Items notification, and you can turn the job off again under Login Items in System Settings.

How is it different from cron?

Three things catch people out. launchd does not run your shell, so ~, $HOME, pipes and your PATH are not there: use full paths, or run /bin/zsh with -c and the whole command. A cron line with ranges or steps, like */15, has to be written out as one start time per entry, which is what the cron box does. And sleep works the other way round: cron skips a run while the Mac sleeps, while a time-of-day job in launchd runs once when the Mac wakes. A job set to every so many seconds (StartInterval) skips a run that falls in sleep, Apple's man page says. Read Apple's guide to launch daemons and agents for the rest.

Questions

How do I run a script every day on a Mac?

Make a launchd plist with StartCalendarInterval set to the hour and minute, put it in ~/Library/LaunchAgents, and load it with launchctl bootstrap. This page writes the file and the commands for you.

Is cron still on macOS?

Yes, cron still works on a Mac, but Apple's docs say it is deprecated in favor of launchd. A cron line can be turned into a launchd plist on this page.

What is the difference between a LaunchAgent and a LaunchDaemon?

A LaunchAgent runs as you while you are logged in, and can show things on screen. A LaunchDaemon runs as root for the whole Mac, from start-up, even when nobody is logged in.

Why does my launchd job not run?

The most common reasons are a path with ~ in it, a program that is not a full path, a script that is not executable, or a plist with a typo. Check the file with plutil -lint, run it once with launchctl kickstart, and read the log files the job writes.

Does a launchd job run if my Mac is asleep?

A job set to a time of day runs once when the Mac wakes, Apple's launchd.plist man page says, and missed runs are joined into one. A job that runs every so many seconds skips a run that falls while the Mac sleeps.

How do I stop a launchd job?

Run launchctl bootout with your domain and the label, like gui/ then your user number, a slash and the label. Then delete the plist file so it does not load again at the next login.

Related