Receiving error code 126 from my launchd job

Viewed 434

I'm in the trying to learn a bit more about launchd and how I can use it to automate some tasks. For some reason when my very simple example job runs it exits with status code 126. I have changed permissions on all of my files to ensure I wasn't the issue (as 126 codes usually have something to do with permissions), but the issue persists.

/Library/LaunchDaemons/test.plst

<?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>test.monday</string>
    <key>Program</key>
    <string>/Users/philliptroutman/Desktop/test.sh</string>
    <key>RunAtLoad</key>
    <true/>
    <key>StartInterval</key>
    <integer>20</integer>
  </dict>
</plist>

/Users/philliptroutman/Desktop/test.sh

#! /bin/sh
echo 'some data' >> /Users/philliptroutman/Desktop/examplefile.txt
echo "some random echo!"

After I load and unload the plst file this is what I get

launchctl unload /Library/LaunchDaemons/test.plist
launchctl load /Library/LaunchDaemons/test.plist
launchctl list | grep test.monday
-   126 test.monday

I guess my question is very simple... why isn't this working?

1 Answers

I was having the same problem with launchd plists that executed from my ~/Documents/scipts folder. The odd think is, they ran fine from a Google Drive folder Documents were linked to but on machines that just had my regular ~/Documents/scripts, they'd fail with error 126. Apple has designated ~/Documents Desktop and Downloads as private directories. Launchd cannot execute scripts from them.

Move the scripts do a different directory like ~/Library/scripts You can always softlink them back to wherever you expected to fine them.

Related