Script management with launchd in Terminal on Mac
The launchd
process is used by macOS to manage daemons and agents, and you can use it to run your shell scripts. You don’t interact with launchd directly; instead you use the launchctl command to load or unload launchd
daemons and agents.
During system startup, launchd
is the first process the kernel runs to set up the computer. If you want your shell script to be run as a daemon, it should be started by launchd
. Other mechanisms for starting daemons and agents are subject to removal at Apple’s discretion.
You can get an idea of the various daemons and agents managed by launchd
by looking at the configuration files in the following folders:
Folder | Usage |
---|---|
/System/Library/LaunchDaemons | Apple-supplied system daemons |
/System/Library/LaunchAgents | Apple-supplied agents that apply to all users on a per-user basis |
/Library/LaunchDaemons | Third-party system daemons |
/Library/LaunchAgents | Third-party agents that apply to all users on a per-user basis |
~/Library/LaunchAgents | Third-party agents that apply only to the logged-in user |