Automator action to run python script on series of files fails in Catalina
Major edit
I've just discovered that the Automator workflow I'm having problems with works perfectly if I run it by pressing 'play' in the Automator window, and it seemingly only fails when I save it as a Quick Action and try and run it by clicking the button in the Preview pane.
Original post
I have an Automator action that iterates through a list of files selected in the Finder, running a python script on each of them in turn. The workflow receives a list of files or folders in the Finder, and then consists of a single 'Run Shell Script' block with 'Pass input: as arguments'.
for f in "$@"
do
/path/to/python_distro /path/to/script.py "$f"
done
In Catalina, this fails with an error:
The action “Run Shell Script” encountered an error: “path/to/python_distro: can't open file '/path/to/script.py': [Errno 1] Operation not permitted
How can I get Catalina to permit this? I've already tried adding Automator to the list of apps that are allowed Full Disk Access, and restarted Automator and killall Finder
'd, but that did not fix my problem.
In my case adding the Finder to the apps having full disk access in system prefs > security & confidentiality > confidentiality tab enabled me to run a Python script (without this I was also getting an "Operation not permitted" error).
Running python scripts in shell scripts seems to work for me. Does the script have executable flags set?
Also, is there any reason you're using a shell script to pass the arguments to the python script, and not just embedding the python script in the Action?
You can set the 'Shell' drop-down value to /usr/bin/python
, to use the bundled system python; or you can just use #!/usr/bin/env python
at the start of your script.
Automator will even help you out by offering:
import sys
for f in sys.argv[1:]:
print f
to get your arguments into your script.