I've been trying to run a python script with a .plist file when my mac starts. I put the file into randomuser/library/launchagents
and at runtime I always get an error saying that it can't open the python file and the operation is not permitted. What can I do to get the script running as intended when my mac boots up? I've looked at a number of forum and stack overflow posts and followed people's advice but I'm always met with the same 'not permitted' errors. I've also tried running a .sh shell but it leads to the same result.
The error I receive:
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file '/Users/randomuser/Documents/Myprogram/startupscript.py': [Errno 1] Operation not permitted
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.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.randomuser.startupscript</string>
<key>Program</key>
<string>/Users/randomuser/Documents/Myprogram/startupscript.py</string>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/randomuser/Documents/Myprogram/log/com.username.scriptname.err</string>
<key>StandardOutPath</key>
<string>/Users/randomuser/Documents/Myprogram/com.username.scriptname.out</string>
</dict>
</plist>
My python file:
#!/usr/bin/env python
import os
import time
while True:
os.system('echo " foo" >> /Users/randomuser/Documents/Myprogram/log/foostore.txt')
time.sleep(1)
It finds the file but can't run it. I've also converted the file into an executable so if I do ./startupscript.py
in the terminal then it will run fine.