Can’t run python script from Automator on Catalina “Operation not permitted”

automatorpythonterminal

I have a service in Automator that I pass a folder and it runs on every file in the folder. It uses a python script to read the album field from an mp3's id3 tags and write it to the Finder comment field:

enter image description here

This worked fine in Mojave, with each file's album being written to its comment. Now with Catalina when I run the service, every comment gets set to the following:

/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file '/Users/thompcha/Documents/Scripts/album.py': [Errno 1] Operation not permitted
  • The script works fine if I run it manually from the terminal
  • I granted Automator, Terminal, and Python full disk access in System Preferences
  • I installed python via Homebrew as suggested in responses to similar questions
  • I made the script chmod 777 and changed the owner to myself

The answer found here does not work for me because I need to pass the output of the python script to the rest of the shell script for further execution.

What can I do to make automator successfully execute my python script?

Best Answer

I ended up in-lining my python script. The finished product looked like this:

for f in "$1"/*.mp3;
do

    updated=$(python -c "import eyed3; import sys; eyed3.log.setLevel(\"ERROR\"); filename = '$f'; from eyed3 import mp3; f = mp3.Mp3AudioFile(filename); album = f.tag.album; f.tag.comments.set(album); f.tag.save(); print(album); exit(album);")

    comment=$(mdls -r -nullMarker "" -n kMDItemFinderComment "$f")

    printf "%s ( comment ): %s\n" "${1##*/}" "$comment"

    /usr/bin/osascript -e "set filepath to POSIX file \"$f\"" \
    -e "set the_File to filepath as alias" \
    -e "tell application \"Finder\" to set the comment of the_File to \"$updated\""

done