I've created a launch agent that uses the find command to look in the downloads folder of a user
files_to_remove=(`cd ~/Downloads/ && find . \( -name "*.csv" -or -name "*.pdf" -or -name "*.sav" -or -name "*.tsv" -or -name "*.zip" -or -name "*.qsf" \) -mtime +5`)
Here is the plist file I've added to the LaunchAgents folder with a 10-second interval to help debug.
<!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>local.downloadsCleanup</string> <key>Program</key> <string>/Library/Application Support/downloadsCleanup/downloadsCleanup.sh</string> <key>RunAtLoad</key> <true/> <key>StandardErrorPath</key> <string>/tmp/downloadsCleanup.err</string> <key>StandardOutPath</key> <string>/tmp/downloadsCleanup.out</string> <key>StartInterval</key> <integer>10</integer> </dict> </plist>
Everytime the LaunchAgent runs is get the error
find: .: Operation not permitted
However, running the
/Library/Application Support/downloadsCleanup/downloadsCleanup.sh script from the terminal prompts me to give permission to the terminal to access the downloads folder. Once the permission is granted the script works as intended.
I've added the .plist file and the .sh script to have full disk access but that that didn't change anything. What do I need to give access for this launchAgent to be able to execute the find command in the downloads folder?