简体   繁体   中英

Trying to run Python script with launchctl / launchd but it won't load. Exit status is 2

I'm trying to run a simple Python script through launchctl every 5 minutes on macOS. I've created my playlist as follows:

<?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.myscript</string>
        <key>ProgramArguments</key>
        <array>
          <string>/Users/me/Documents/myscript.py</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>StartInterval</key>
        <integer>300</integer>
    </dict>
  </plist>

However, the script never runs. I've loaded and unloaded it multiple times. Executing the command

/Users/me/Documents/myscript.py

works just fine, since I added '#!/usr/bin/env python' to the beginning of the Python script. If I run launchctl -l, I see:

    -     2   com.myscript

I'm not sure what an exit status of 2 means. Can anyone help?

I got this working by using cron (which previously wasn't working either) and moving the script in question to the root of my Home folder instead of the Documents folder. I think the issue is macOS Catalina's new restrictions on access to files in the Documents or Desktop folders. Moving the script elsewhere seems to resolve it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM