I am trying to accomplish running a script on startup on OSX. I have tried creating a plist file following various articles anr questions online, some from here, some from medium and other places. But I just can't seem to get it right. I want the script to run anytime the computer is started, regardless of which user logs on. The script is a simple bash script which checks for the existence of an object in an S3 bucket, and if that object exists, it continues and then obviously runs the rest of the script (in this case, a cleanup script).
Here is my plist file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.$
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:</string>
</dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.cleanup</string>
<key>Program</key>
<string>/bin/zsh</string>
<key>ProgramArguments</key>
<string>/Users/mlove/Documents/gitpersonal/ejector-seat/cleanup</string>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/startup.stderr</string>
<key>StandardOutPath</key>
<string>/tmp/startup.stdout</string>
<key>UserName</key>
<string>mlove</string>
</dict>
</plist>
and here is the script I want to invoke:
#!/bin/zsh
aws s3api wait object-exists --bucket ejector-seat --key button-pressed --profile parachute
rm -rf /Users/${USER}/Desktop/test/*
Edit:
I missed out my error logs which are full of the following:
/bin/zsh: can't open input file: /Users/mlove/Documents/gitpersonal/ejector-seat/cleanup
I tried making the script 777 just for testing but still getting the error, and if I run the script manually by simply doing ./cleanup
it runs fine, so I know that the script itself is ok, so I think it is something to do with the way I am invoking it inside the plist file.
I must be missing something simple I'm sure, any assistance would be appreciated!