2

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?

2

Yes, you need to use

System Preferences -> Security and Privacy -> Privacy -> Files & Folders

Or maybe you can specify "Full Disk Access" for the last element there.

Grant /bin/bash access, and it should work.

1
  • I added /bin/sh to "Full Disk Access" and it worked! Thanks! – Josh Mar 23 '20 at 17:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .