Reputation: 152
I'm trying to write a launchd
script that will run a Python script every hour.
I created the following file in ~/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>
I then run:
launchctl load ~/Library/LaunchAgents/com.b00tahead.engage-check.plist
launchctl start com.b00tahead.engage-check
When I run launchctl list
it shows the process as:
PID Status Label
- 2 com.b00tahead.engage-check
I'm not exactly sure what that return code indicates. I can run the script just fine through the terminal as python3 Projects/engage_scripts/engage_check.py
The Python script writes some data to a .txt file on my desktop.
This is what launchctl list com.b00tahead.engage-check
returns:
{
"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";
);
};
Upvotes: 2
Views: 3728
Reputation: 166319
My guess is that the argument in ProgramArguments
should have an absolute path (not relative such as Projects/...
).
In case of error, system log should be checked, e.g.
tail -f /var/log/system.log
or custom log can be used by specifying these lines:
<key>StandardOutPath</key>
<string>/var/log/myjob.log</string>
<key>StandardErrorPath</key>
<string>/var/log/myjob.log</string>
See: Debugging launchd Jobs section of Creating Launch Daemons and Agents page.
Upvotes: 2