2016-09-14 17:29:12 +01:00
# launchctl
2023-07-16 18:23:40 +01:00
> Control Apple's `launchd` manager for launch daemons (system-wide services) and launch agents (per-user programs).
2016-09-14 17:29:12 +01:00
> `launchd` loads XML-based `*.plist` files placed in the appropriate locations, and runs the corresponding commands according to their defined schedule.
2024-01-31 10:20:27 +00:00
> More information: <https://keith.github.io/xcode-man-pages/launchctl.1.html>.
2016-09-14 17:29:12 +01:00
- Activate a user-specific agent to be loaded into `launchd` whenever the user logs in:
`launchctl load ~/Library/LaunchAgents/{{my_script}}.plist`
- Activate an agent which requires root privileges to run and/or should be loaded whenever any user logs in (note the absence of `~` in the path):
`sudo launchctl load /Library/LaunchAgents/{{root_script}}.plist`
- Activate a system-wide daemon to be loaded whenever the system boots up (even if no user logs in):
`sudo launchctl load /Library/LaunchDaemons/{{system_daemon}}.plist`
- Show all loaded agents/daemons, with the PID if the process they specify is currently running, and the exit code returned the last time they ran:
`launchctl list`
2024-02-05 07:04:49 +00:00
- Unload a currently loaded agent, e.g. to make changes (Note: the plist file is automatically loaded into `launchd` after a reboot and/or logging in):
2016-09-14 17:29:12 +01:00
`launchctl unload ~/Library/LaunchAgents/{{my_script}}.plist`
2024-02-05 07:04:49 +00:00
- Manually run a known (loaded) agent/daemon, even if it is not the right time (Note: this command uses the agent's label, rather than the filename):
2016-09-14 17:29:12 +01:00
2023-02-20 07:05:58 +00:00
`launchctl start {{script_file}}`
2016-09-14 17:29:12 +01:00
2019-02-24 23:56:24 +00:00
- Manually kill the process associated with a known agent/daemon, if it is running:
2016-09-14 17:29:12 +01:00
2023-02-20 07:05:58 +00:00
`launchctl stop {{script_file}}`