我正在尝试编写一个launchd
每小时运行一个 Python 脚本的脚本。
我在~/Library/LaunchAgents/
com.b00tahead.engage-check.plist
<?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>com.b00tahead.engage-check</string>
<key>ProgramArguments</key>
<array>
<string>/Library/Frameworks/Python.framework/Versions/3.5/bin/python3</string>
<string>Projects/engage_scripts/engage_check.py</string>
</array>
<key>StartInterval</key>
<integer>3600</integer>
</dict>
</plist>
然后我运行:
launchctl load ~/Library/LaunchAgents/com.b00tahead.engage-check.plist
launchctl start com.b00tahead.engage-check
当我运行launchctl list
它时,它显示该过程为:
PID Status Label
- 2 com.b00tahead.engage-check
我不确定该返回码表示什么。我可以通过终端很好地运行脚本python3 Projects/engage_scripts/engage_check.py
Python 脚本将一些数据写入我桌面上的 .txt 文件。
这是launchctl list com.b00tahead.engage-check
返回:
{
"LimitLoadToSessionType" = "Aqua";
"Label" = "com.b00tahead.engage-check";
"TimeOut" = 30;
"OnDemand" = true;
"LastExitStatus" = 512;
"Program" = "/Library/Frameworks/Python.framework/Versions/3.5/bin/python3";
"ProgramArguments" = (
"/Library/Frameworks/Python.framework/Versions/3.5/bin/python3";
"Projects/engage_scripts/engage_check.py";
);
};