launchd
Linux systemd == Macos launchd
-
Manuals:
man launchctl|man launchd
Scheduling a script (zettelmerken) to run at specific time
-
Create a new file
com.zettelmerken.dailyreview.plistin~/Library/LaunchAgents/ -
Add the following xml to it:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.zettelmerken.dailyreview</string> <key>ServiceDescription</key> <string>Zettelmerken Daily Review</string> <key>ProgramArguments</key> <array> <string>/opt/homebrew/bin/python3</string> <string>-m</string> <string>zettelmerken</string> </array> <!-- Run on load (at bootup) --> <key>RunAtLoad</key> <true /> <!-- Run Daily at 00:10 min --> <key>StartCalendarInterval</key> <dict> <key>Hour</key> <integer>0</integer> <key>Minute</key> <integer>10</integer> </dict> <!-- For Debugging <key>StandardErrorPath</key> <string>/tmp/com.zettelmerken.dailyreview.err</string> <key>StandardOutPath</key> <string>/tmp/com.zettelmerken.dailyreview.out</string> --> </dict> </plist> -
Verify
plutil ~/Library/LaunchAgents/com.zettelmerken.dailyreview.plist -
Load agent
launchctl load -w ~/Library/LaunchAgents/com.zettelmerken.dailyreview.plist -
Unload agent
launchctl unload -w ~/Library/LaunchAgents/com.zettelmerken.dailyreview.plist -
Start/Stop (for debugging)
launchctl start com.zettelmerken.dailyreview -
List all services
launchctl list