Adapt the following accordingly, name it something like myscript_launcher.plist
, and put it in either one of three locations: /System/Library/LaunchAgents
, /System/Library/LaunchDaemons
, /Users/<username>/Library/LaunchAgents
.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>my.python.script.name</string>
<key>ProgramArguments</key>
<array>
<string>/path/to/python</string>
<string>/path/to/python/script.py</string>
</array>
<key>StandardErrorPath</key>
<string>/var/log/python_script.error</string>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
Also, let's assume you put the plist file in ~/Library/LaunchAgents
. You can start and stop it with the launchctl
. To start, use launchctl load ~/Library/LaunchAgents/myscript_launcher.plist
. To stop it, do the same but use the unload
argument
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…