0

I was hoping someone could point out where I might be going wrong with a launchctl script I'm trying to write and launch.

The intention is to run a python script I've managed to get working, everyday at 3.15am. (the computer it's going to run on is on 24/7 but if there is a way to incorporate this into it's everyday running that would be great in the event the computer shuts down or needs to be interrupted.)

When I attempt to load the file I get the return message below:

jace@Jaces-Mac-Pro ~ % launchctl load /Users/jace/Library/LaunchAgents/com.launchd.phoneconfig.plist
/Users/jace/Library/LaunchAgents/com.launchd.phoneconfig.plist: Invalid property list
jace@Jaces-Mac-Pro ~ % 

According to the tutorial I'm following and a few pages online I've reviewed I should have laid everything out correctly but feel I'm missing something.

If someone could point out my mistake and offer a solution I'd really appreciate it!

Am totally new to this file type and the writing of, but feel it'll be what i need to get the job done.

The file I'm trying to run is the below -

<?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.launch.phoneconfig</string>
       <key>ProgramArgument</key>
    <array>
        <string>/usr/local/bin/python3</string>
        <string>/Users/jace/Desktop/Filing_Cabinet/Python_Folder/Selenium_Projects/my_phone_config01.py</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key
        <integer>3</integer>
        <key>Minute</key>
        <integer>15</integer>
    </dict>
</dict>
</plist>1

P.s

I tried putting the file in my mac's launch Daemon folder but can't seem to locate it in the Library, only 'LaunchAgents' folder can be found. Don't know if this effects anything but let me know if there's more information I could provide to get this running.

Thank you for your time.

I was hoping the code to load and run at the designated time and be returned with the other .plist files when I enter 'launchctl list' into terminal.

Update from comment

(Thanks for pointing this out @Chepner) Running 'putil -lint' allowed me to see an error in script. Example of result.

Before, w/error:

jace@Jaces-Mac-Pro LaunchAgents % plutil /Users/jace/Library/LaunchAgents/com.launchd.phoneconfig.plist
/Users/jace/Library/LaunchAgents/com.launchd.phoneconfig.plist: Encountered unexpected character < on line 17 while looking for close tag

After, once fixed:

jace@Jaces-Mac-Pro LaunchAgents % plutil -lint /Users/jace/Desktop/Filing_Cabinet/LaunchD_Folder/launch_phoneconfig/com.launchd.phoneconfig.plist
/Users/jace/Desktop/Filing_Cabinet/LaunchD_Folder/launch_phoneconfig/com.launchd.phoneconfig.plist: OK

Tried running code again but results are as shown -

jace@Jaces-Mac-Pro LaunchAgents % launchctl load /Users/jace/Desktop/Filing_Cabinet/LaunchD_Folder/launch_phoneconfig/com.launchd.phoneconfig.plist
/Users/jace/Desktop/Filing_Cabinet/LaunchD_Folder/launch_phoneconfig/com.launchd.phoneconfig.plist: Invalid or missing Program/ProgramArguments
jace@Jaces-Mac-Pro LaunchAgents % 

Update from Answer

Thank you for the suggestion @Chepner.

Adjusting the line to separate the program and program argument seems to have gotten everything to say 'ok'. Technically this answers my question!

Only problem now is that it doesn't actually run, I can run the python script it's meant to run just fine but can't seem to get it to run via this method. Any suggestions or links I can review to help figure this out?

Thank you for your time in helping me! :)

Last login: Wed Nov 30 14:44:29 on console
jace@Jaces-Mac-Pro ~ % plutil /Users/jace/Library/LaunchAgents/com.launchd.phoneconfig.plist

/Users/jace/Library/LaunchAgents/com.launchd.phoneconfig.plist: OK

jace@Jaces-Mac-Pro ~ % launchctl list
PID Status  Label
-   0   com.launch.phoneconfig (removed the other items that would be returned to show clearly it loaded)
jace@Jaces-Mac-Pro ~ % 
JaceExton
  • 15
  • 6
  • Use `plutil -lint` to check your file for errors. You are missing the closing `>` for the `` tag on line 17. – chepner Nov 28 '22 at 15:22
  • Please update the question to reflect this; there are no existing answers to invalidate by fixing the missing `>`, so we can just pretend that your current problem is your original problem. – chepner Nov 28 '22 at 17:03
  • Thanks Chepner, have done so above now. :) – JaceExton Nov 28 '22 at 17:10
  • The script is scheduled to run at 0315, no? – chepner Nov 30 '22 at 15:18
  • it is but I changed it to test it out over lunch to a time I should be able to view it executing the script but nothing happened. I also applied 'launchctl start' to the script to manually push it through and nothing happened. – JaceExton Nov 30 '22 at 18:15

1 Answers1

1

I think the problem is that you are trying to specify an entire command line as program arguments, rather than specifying the program name separately from its arguments.

<dict>
    <key>Label</key>
      <string>com.launch.phoneconfig</string>
    <key>Program</key>
      <string>/usr/local/bin/python3</string>
    <key>ProgramArgument</key>
      <array>
        <string>/Users/jace/Desktop/Filing_Cabinet/Python_Folder/Selenium_Projects/my_phone_config01.py</string>
      </array>
    <key>RunAtLoad</key>
      <true/>
    <key>StartCalendarInterval</key>
      <dict>
        <key>Hour</key
        <integer>3</integer>
        <key>Minute</key>
        <integer>15</integer>
      </dict>
</dict>

If this is the case, the runtime error could be more specific (Program is missing, so it could just say so instead of implying that there is a problem with ProgramArguments as well).

chepner
  • 497,756
  • 71
  • 530
  • 681
  • Thanks for the help Chepner! (",) Have updated my question to reflect the update, now all that's left to do is figure out why my script won't run. ('-.-) – JaceExton Nov 30 '22 at 15:13