Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to fix "Operation not permitted" when i use launchctl in macos catalina

Tags:

python

sh

macos

I'm setting up a launchctl server to run a python file regularly. So I write a.plist file , auto.sh file and it works well. However, after I installed Macos Catalina, it failed. I write "ls -l" in auto.sh to check file permission, log shows that:

ls: .: Operation not permitted
python3: can't open file 'auto.py': [Errno 1] Operation not permitted 

How can I do to fix it? Thank you so much.

here is my code:

auto.sh:

#!/bin/bash
. ~/.bash_profile
conda activate base
cd /Users/gassy/Documents/
ls -l
python3 auto.py

I put such .plist file in /Users/gassy/Library/LaunchAgents/com.gassy.fangzhou.plist

    ...
    <key>Program</key>
    <string>/Users/gassy/auto/launch.sh</string>
    ...
like image 926
Lucas Avatar asked Oct 18 '19 01:10

Lucas


2 Answers

Finally figure it out...

It's a problem related to Catalina new permission system, the /bin/bash need to have the [full disk access].

enter image description here

like image 154
mingxin Avatar answered Sep 26 '22 02:09

mingxin


I think the problem you have is not with Python, but with the file permissions on auto.py or the path leading up to it. What user account is used to run the script? Does that user have the necessary permissions on both those executables and the parent directory? Reason I suspect directory permissions is that ls is failing along with auto.py.

You might have some luck if you move everything out of /Users/gassy/Documents and to another location, perhaps under /opt or /var or similar, and then make sure that the permissions are sane. I know that macos treats some of those directores under /Users/<user> special, sometimes in a less-than-helpful way...

like image 28
Z4-tier Avatar answered Sep 24 '22 02:09

Z4-tier