2020-11-17 16:48:58 +00:00
|
|
|
|
# launchctl
|
2017-06-04 14:03:11 +00:00
|
|
|
|
# A command-line interface to Apple's launchd manager
|
2020-11-17 16:48:58 +00:00
|
|
|
|
#
|
|
|
|
|
# for launch daemons (system-wide services) and launch agents (per-user
|
|
|
|
|
# programs). launchd loads XML-based *.plist files placed in the appropriate
|
|
|
|
|
# locations, and runs the corresponding commands according to their defined
|
|
|
|
|
# schedule.
|
2017-06-04 14:03:11 +00:00
|
|
|
|
|
2020-11-17 16:48:58 +00:00
|
|
|
|
# Activate user-specific agent to load into launchd whenever the user logs in.
|
2017-06-04 14:03:11 +00:00
|
|
|
|
launchctl load ~/Library/LaunchAgents/my_script.plist
|
|
|
|
|
|
2020-11-17 16:48:58 +00:00
|
|
|
|
# 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).
|
2017-06-04 14:03:11 +00:00
|
|
|
|
sudo launchctl load /Library/LaunchAgents/root_script.plist
|
|
|
|
|
|
2020-11-17 16:48:58 +00:00
|
|
|
|
# Activate a system-wide daemon to be loaded whenever the system boots up, -
|
|
|
|
|
# even if no user logs in.
|
2017-06-04 14:03:11 +00:00
|
|
|
|
sudo launchctl load /Library/LaunchDaemons/system_daemon.plist
|
|
|
|
|
|
2020-11-17 16:48:58 +00:00
|
|
|
|
# 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.
|
2017-06-04 14:03:11 +00:00
|
|
|
|
launchctl list
|
|
|
|
|
|
2020-11-17 16:48:58 +00:00
|
|
|
|
# Unload a currently-loaded agent to, for example, make changes. The plist file
|
|
|
|
|
# is automatically loaded into launchd after a reboot and/or logging in.
|
2017-06-04 14:03:11 +00:00
|
|
|
|
launchctl unload ~/Library/LaunchAgents/my_script.plist
|
|
|
|
|
|
|
|
|
|
# Manually run a known (loaded) agent/daemon, even if it isn’t the right time
|
2020-11-17 16:48:58 +00:00
|
|
|
|
# This command uses the agent's label, rather than the filename.
|
2017-06-04 14:03:11 +00:00
|
|
|
|
launchctl start my_script
|
|
|
|
|
|
2020-11-17 16:48:58 +00:00
|
|
|
|
# Manually kill the process associated with a known agent/daemon, if running.
|
2017-06-04 14:03:11 +00:00
|
|
|
|
launchctl stop my_script
|