Mac daemon not able to run bash script Originally asked on Stack Overflow, but it may be more suited for here. Wherever it’s answered first, I’ll be sure to update the counterpart question with the same answer.
I've already checked this similar question.

OS MacOS 10.15.17 (Catalina)

I want to create a script that uses iperf to launch a client that measures my connection speed every several seconds for an extended period. I’ve created a daemon file and put it in ~/Library/LaunchAgents/com.myself.iperfclient.plist.
com.myself.iperfclient.plist
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;
&lt;plist version=&quot;1.0&quot;&gt;
    &lt;dict&gt;
        &lt;key&gt;Label&lt;/key&gt;
        &lt;string&gt;com.myself.iperfclient&lt;/string&gt;
        
        &lt;key&gt;ProgramArguments&lt;/key&gt;
        &lt;array&gt;
            &lt;string&gt;/Users/myself/Documents/bin/iperf/netspeed&lt;/string&gt;
        &lt;/array&gt;

        &lt;key&gt;StartInterval&lt;/key&gt;
        &lt;integer&gt;20&lt;/integer&gt;  &lt;!-- in seconds --&gt;

        &lt;key&gt;Disabled&lt;/key&gt;
        &lt;false/&gt;
    &lt;/dict&gt;
&lt;/plist&gt;

netspeed
#!/bin/bash


# see https://stackoverflow.com/a/246128/10200417
script_dir=&quot;$( cd &quot;$( dirname &quot;${BASH_SOURCE[0]}&quot; )&quot; &gt;/dev/null 2&gt;&amp;1 &amp;&amp; pwd )&quot;
script_name=`basename $0`
# echo &quot;called script $script_name from $script_dir&quot;

iperf_server=127.0.0.1
iperf_port=54321

# launch iperf client, log results to ./logs/client.log
iperf \
    -c $iperf_server \
    -p $iperf_port \
    --logfile $script_dir/logs/client.log

The netspeed file is executable for anyone:
$ ls -l netspeed
  -rwxr-xr-x@ 1 myself  staff  379 Jan 11 21:36 netspeed

When I try to add the new daemon, with launchctl load ~/Library/LaunchAgents/com.myself.iperfclient.plist, this is the error message I get in the Console:
Sandbox: bash(50654) System Policy: deny(1) file-read-data /Users/myself/Documents/bin/iperf/netspeed

If in the .plist descriptor for the daemon I add &lt;string&gt;open&lt;/string&gt; as the first item in ProgramArguments, there’s no error. However, I don’t want to run the script this way because it launches a new Terminal window every time, which is extremely annoying.
My question
How do I allow my daemon process to execute netspeed?
P.S.
The launchctl status code is 126.
$ launchctl list | grep myself
-   126 com.myself.iperfclient
Alright, here’s what I ended up doing, which does work and doesn’t require any other installations. I tried the answer from Gilby, but wasn’t able to get fdautil to work after downloading and installing it via the LaunchControl trial version.
If it had worked, it seems it would have done so by granting LaunchControl’s fdautil utility full disk access, which would then use those permissions somehow to execute my netspeed script (without passing those permissions to /bin/bash?).
Method 1: AppleScript wrapper
I created Users/myself/Documents/bin/iperf/netspeed.scpt, which has the following:
do shell script &quot;/Users/myself/Documents/bin/iperf/netspeed&quot;

I then updated the ProgramArguments entry in the launchd plist to:
&lt;key&gt;ProgramArguments&lt;/key&gt;
&lt;array&gt;
    &lt;string&gt;/usr/bin/osascript&lt;/string&gt;
    &lt;string&gt;/Users/myself/Documents/bin/iperf/netspeed.scpt&lt;/string&gt;
&lt;/array&gt;

Finally, in System Preferences &gt; Security and Privacy &gt; Files and Folders I was able to grant access for Users/myself/Documents to /usr/bin/osascript, and successfully launch the daemon.
Method 2: Put script in location with less security
As @user3439894 pointed out, since the main reason it was difficult to execute netspeed in the first place was that I had it in ~myself/Documents.../, which has elevated permissions requirements, I can also just put it in a location with less security.
I followed the suggestion to try /Users/Shared/.../netspeed and it indeed worked with my original script and plist contents! To be clear, the ProgramArguments would now be:
&lt;key&gt;ProgramArguments&lt;/key&gt;
&lt;array&gt;
    &lt;string&gt;/Users/Shared/.../netspeed&lt;/string&gt;
&lt;/array&gt;