Intro
- From The Missing Semester:
You are probably already familiar with the notion of daemons, even if the word seems new. Most computers have a series of processes that are always running in the background rather than waiting for a user to launch them and interact with them. These processes are called daemons and the programs that run as daemons often end with a
d
to indicate so. For examplesshd
, the SSH daemon, is the program responsible for listening to incoming SSH requests and checking that the remote user has the necessary credentials to log in.
Links
- Apple documentation
- A launchd tutorial
- How to Use launchd to Run Scripts on Schedule in macOS
- Another cool tutorial, even if specifically about Git
- How to Trigger Any Action When a File or Folder Changes
Notes
launchd
runs scheduled jobs after the computer wakes up,cron
does not (but it can be useful sometimes)launchd
differentiates between agents and daemons. The main difference is that an agent is run on behalf of the logged in user while a daemon runs on behalf of the root user or any user you specify with theUserName
key.- If you see
</true>
inplist
, it specifies value for boolean key, likeRunAtLoad
- Commands from here
- Make sure your filename ends in
.plist
, e.g./Users/johnny/Library/LaunchAgents/com.appleseed.runthings.plist
- Check the syntax of the file:
plutil /Users/johnny/Library/LaunchAgents/com.appleseed.runthings.plist
- Unload and reload your service:
launchctl unload /Users/johnny/Library/LaunchAgents/com.appleseed.runthings.plist
launchctl load /Users/johnny/Library/LaunchAgents/com.appleseed.runthings.plist
- Force load in case your job has been disabled:
launchctl load -w /Users/johnny/Library/LaunchAgents/com.appleseed.runthings.plist
- Make sure your filename ends in
- To check if it's running, do
launchctl list | grep com.appleseed.runthings
- If you don't see status
0
, see help on errors vialaunchctl error <error code>
- Some of my previous errors and their solution:
- error
78
:- these solutions lead to this
launchd
plist generator to fix - Essentially, you better run any scripts (even bash) through
ProgramArguments
and add by what it should be run - error
126
: - Python functions not recognised
- change
PATH
same as here
- change
- these solutions lead to this
- error