A launch agent is a background job that the launchd service manager starts and supervises on behalf of a logged-in user in macOS. Each agent is described by a property list (plist) file stored in a LaunchAgents folder, and launchd reads that file to decide what program to run, when to run it and whether to restart it after it exits.
In the Terminal & scripting toolset, launch agents are the native replacement for cron and login scripts. They run inside the user’s GUI session, so they can reach the user’s home folder, keychain and window server, which separates them from a launch daemon that runs system-wide before anyone logs in.
How launchd loads and runs a launch agent
A launch agent works by registering a job definition with launchd, which then owns the life cycle of the process. When a user logs in, launchd creates a per-user domain (named gui/<uid> for a graphical login) and loads every valid plist found in the agent folders that apply to that user.
The plist does not contain code. It names an executable through the Program or ProgramArguments key and lists launch conditions such as RunAtLoad, StartInterval, StartCalendarInterval, WatchPaths or KeepAlive. Launchd keeps the job registered even while the process is not running, and it starts the process on demand when a condition is met. This on-demand model saves memory and battery compared with a script that loops forever.
Agents are loaded from three locations, and the folder decides who the agent runs for and who may edit it. The table below summarizes the scope of each location.
| Folder | Runs for | Who installs it |
|---|---|---|
| ~/Library/LaunchAgents | The owning user only | The user or the user’s apps |
| /Library/LaunchAgents | Every user who logs in | An administrator or an installer package |
| /System/Library/LaunchAgents | Every user, managed by Apple | macOS itself, protected by SIP |
Since macOS Ventura, apps can also register helper agents bundled inside the app through the SMAppService API. Those agents appear in System Settings under Login Items & Extensions, where the user can switch background activity off.
Key plist keys that control behavior
A launch agent’s behavior is defined entirely by keys in its property list, and a small set of keys covers most real jobs. The Label key is mandatory and must be unique within the domain; by convention it uses reverse-DNS notation such as com.example.backup, and the file name usually matches it.
| Key | Purpose | Typical value |
|---|---|---|
| Label | Unique job identifier | com.example.sync |
| ProgramArguments | Executable path and its arguments | Array of strings |
| RunAtLoad | Start once when the job loads | true or false |
| StartInterval | Run every N seconds | 300 to 86400 |
| StartCalendarInterval | Run at a clock time, like cron | Hour 2, Minute 30 |
| KeepAlive | Restart the process if it exits | true or a condition dictionary |
| WatchPaths | Run when a file or folder changes | Array of paths |
| StandardOutPath | File that receives output | /tmp/job.log |
Two details cause most confusion. First, launchd does not expand the tilde or shell variables, so paths must be absolute. Second, launchd throttles respawning: by default a job cannot be relaunched more often than every 10 seconds (ThrottleInterval), which protects the system from a crashing process that would otherwise restart in a tight loop.
Launch agent compared with related mechanisms
A launch agent differs from neighboring mechanisms mainly in which session it runs in and what triggers it. The comparison below places it among the tools an administrator or power user is likely to consider.
| Mechanism | Runs as | Trigger | Best for |
|---|---|---|---|
| Launch agent | Logged-in user | Login, schedule, file change, demand | Per-user automation and helpers |
| Launch daemon | root or a service account | Boot, schedule, network demand | System services without a user |
| cron | User or root | Clock schedule only | Legacy scripts ported from Unix |
| Login item | Logged-in user | Login only | Opening visible apps at login |
| Shortcuts automation | Logged-in user | Events defined in Shortcuts | Simple tasks without plist editing |
Apple treats cron as deprecated in favor of launchd, although it still works. A key advantage of launchd is missed-run handling: if the Mac was asleep at the time set in StartCalendarInterval, the job runs when the Mac wakes, whereas cron simply skips the missed run.
Loading and managing agents with launchctl
Launch agents are managed from Terminal with the launchctl command, which talks directly to launchd. Modern macOS versions use the domain-target syntax; the older load and unload subcommands still exist but are considered legacy and report errors less clearly.
- Create the plist in
~/Library/LaunchAgentsand validate it withplutil -lint. - Load it with
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.example.sync.plist. - Inspect state with
launchctl print gui/$(id -u)/com.example.sync. - Start it immediately with
launchctl kickstart -k gui/$(id -u)/com.example.sync. - Remove it with
launchctl bootout gui/$(id -u)/com.example.sync.
The print output shows the last exit code, the run count and the active triggers, which makes it the first diagnostic step when an agent does not behave as expected. Editing a plist has no effect until the job is booted out and bootstrapped again.
Common mistakes and security considerations
Most launch agent failures come from environment differences between Terminal and launchd. A job started by launchd receives a minimal PATH and none of the settings from the user’s shell profile, so a script that works interactively may fail silently in the background.
| Symptom | Likely cause | Fix |
|---|---|---|
| Job never starts | Invalid plist or wrong ownership | Run plutil -lint and set correct owner |
| Exit code 127 | Command not found in PATH | Use absolute paths or set EnvironmentVariables |
| Operation not permitted | Privacy protection blocks file access | Grant Full Disk Access to the executable |
| Job restarts constantly | KeepAlive with a crashing process | Fix the crash or use a conditional KeepAlive |
| Changes ignored | Plist edited but not reloaded | Boot out and bootstrap the job again |
Because agents start automatically, they are a common persistence technique for malware. macOS shows a background item notification whenever a new agent is added, and endpoint security tools monitor the LaunchAgents folders closely. Administrators should review unknown labels with sfltool dumpbtm and remove agents whose executables are unsigned or point to unexpected locations.
The simple explanation
A launch agent is like a standing instruction left with a personal assistant. The instruction says what to do and when: every morning, whenever a certain folder changes, or as soon as you sign in. The assistant, which is a built-in part of macOS, remembers it and carries it out without you opening anything.
The instruction lives in a small text file. Because it belongs to your account, the task runs only while you are logged in and can use your files. The key point is that a launch agent lets a Mac do routine work on its own, reliably and quietly in the background.
How it is used in practice
A video editor keeps active projects on an external SSD and wants an automatic copy every evening. She writes a short shell script that uses rsync to mirror the project folder to a network share, then creates a plist labeled com.studio.nightlysync in her LaunchAgents folder with StartCalendarInterval set to hour 21, minute 0 and StandardErrorPath pointing to a log file.
After loading it with launchctl bootstrap, the first run fails with exit code 127 because rsync from Homebrew is not in launchd’s default PATH. She replaces the command with its full path, reloads the job and confirms success with launchctl print. On nights when the laptop is closed at 21:00, the copy runs when it wakes. The result is a dependable nightly backup that requires no manual steps.