MacOS – Allow Shell Script to Access Protected Library Folders (launchd)

bashlaunchdmacospermission

I'm trying a bash script that works fine when run from the command line (Terminal).

Apart from the shebang, it just has:

ls -alt /Users/<username>/Libary/Mail/V6/.../Lists.mbox

(Using ls as a simple command to illustrate the problem.)

However, when I try a test run using launchd (which I set up using the Lingon X app) I get a permissions error.

1: Operation not permitted
ls: Lists.mbox: Operation not permitted

Terminal and Lingon X both have Full Disk Access allowed in Privacy pref pane, but I don't see any way to allow an individual shell script to be given such access.

I've tried running the same script using AppleScript's do shell script but I get the same error.

The (.sh) script permissions are set to 755, so this should not be a factor.

How can I get around this please?

Best Answer

I overcame the issue by creating an application wrapper for the script using Platypus - https://sveinbjorn.org/platypus.

I gave the resultant app Full Disk Access in the Privacy pref pane and this allowed it to run.

(Any subsequent change to the core script means regenerating the app and removing and re-adding it in Privacy as the new file is not recognised as having Full Disk Access.)