How to fix LaunchAgent scandir: [Errno 1] Operation not permitted error

launchd

<key>ProgramArguments</key>
<array>
  <string>/usr/local/bin/backup.sh</string>
</array>

Running /usr/local/bin/backup.sh requires access to ~/Documents.

My gut feeling is I have to allow an app in "Security & Privacy", but which one and is that secure?

Best Answer

The following worked!

I created an app using "Script Editor" that runs /usr/local/bin/borg-backup.sh using zsh.

do shell script "zsh /usr/local/bin/borg-backup.sh"

I then exported the app to /Applications/borg-backup.app clicking "File" then "Export..." choosing "Application" for "File Format".

Finally, I updated ~/Library/LaunchAgents/local.borg-backup.plist.

<key>ProgramArguments</key>
<array>
  <string>open</string>
  <string>/Applications/borg-backup.app</string>
</array>

The first time the launch agent ran, a prompt asked me to grant borg-backup.app access to ~/Documents.