MacOS Catalina causing “find: .: Operation not permitted” errors

automatorcatalinafinderterminal

I have an automation workflow that I use as a Quick Action. It takes a Finder item and calls a shell script with it. Part of the shell script runs a find command on the directory of the Finder item. Prior to Catalina, this worked. Now I get

find: <path to the directory>: Operation not permitted

This only happens when I'm running it as the Service Quick Action. If I call the script in Terminal, it works fine, as does the find command in Terminal.

# Directory to delete files from
REAL_FILE=$(/usr/local/bin/realpath "$1")
DIR=$(dirname "$REAL_FILE")

find "$DIR" -type f -depth 1 -print0 | while read -d $'\0' FILE
do
    if [[ "$FILE" < "$REAL_FILE" ]] ; then
        mv "$FILE" ~/.Trash/
    fi
done

Best Answer

You need to grant the Finder full disk access:

  1. Open Security & Privacy preferences
  2. Go to the Full Disk Access option.
  3. Click the plus button.
  4. Locate the Finder in /System/Library/CoreServices/ (or simply type 'Finder' into Search).

Compare Grant “Full Disk Access” to Workflows run via the Services menu.