0

I have created a .plist file in order to run a Python program when I start up my Mac. The following is my .plist file, myprogram.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>myprogram.name</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/louiscage/PycharmProjects/myprogram/myprogram.command</string>
   </array>
   <key>RunAtLoad</key>
   <true/>
</dict>
</plist>

The string in the .plist file is the path to my Python script, which I had made executable by using "chmod +x" in the terminal.

However, when I enter

launchctl load /Library/LaunchAgents/myprogram.plist

into the terminal, which is the path to my .plist file, there doesn't seem to be any errors. This leads me to believe my .plist was loaded successfully to LaunchD. But when I enter

launchctl start /Library/LaunchAgents/myprogram.plist

, my program does not start.

Also, when I restart my Mac, the program still does not start, even if I had loaded it to LaunchD.

Any help towards why this .plist file does not start using LaunchD would be greatly appreciated.

5
  • My guess is that the script is crashing or exiting early, but you need to do some troubleshooting to find out for sure. First, what does launchctl list myprogram.name (note that this uses the Label, not the filename) show? Look particularly for "PID" = (which would indicate it's running) and "LastExitStatus" = (if nonzero, that means the program errored out last time it was run). Also, add StandardOutPath and StandardErrorPath to the plist pointing to log files, unload and reaload it, and see what they contain. Commented Jun 6, 2020 at 0:26
  • Thank you for your reply. I'm sorry, I understand that I include <key>StandardErrorPath</key> and <key>StandardOutPath</key> underneath the <true/> in my .plist. But what do you mean by "to the plist pointing to log files"? Commented Jun 6, 2020 at 1:05
  • See the launchd.plist man page about those keys, and my answer here for an example of how to use them for debugging. Commented Jun 6, 2020 at 2:08
  • Thank you for your help. I made two .txt. files and made the extension ".log". I then put the path to these files under the "StandardErrorPath" and "StandardOutPath" in my .plist file. So now when I run my .plist through launchd, it will report any errors to these .log files? Commented Jun 8, 2020 at 2:45
  • It'll put the sorts of output that'd normally go to your Terminal window to those files. There's a good chance that'll include error messages, but it really depends on the Python script. If it doesn't have anything informative, you might have to add some print statements to your script to indicate what's going on (and hopefully point to what's wrong). Oh, and did you check launchctl list myprogram.name? That should give at least a little info about what's happening. Commented Jun 8, 2020 at 2:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.