我正在尝试编写一个每小时运行一次Python脚本的launchd
脚本。
我在~/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";
);
};
答案 0 :(得分:0)
我的猜测是ProgramArguments
中的参数应该有一个绝对路径(不是Projects/...
之类的相对路径。)
如果出现错误,应检查系统日志,例如
tail -f /var/log/system.log
通过指定以下行可以使用或自定义日志:
<key>StandardOutPath</key>
<string>/var/log/myjob.log</string>
<key>StandardErrorPath</key>
<string>/var/log/myjob.log</string>
请参阅:Debugging launchd Jobs section of Creating Launch Daemons and Agents page。