Run script as root at startup - macOS 10.12 Sierra I've tried everything and can't seem to get my script to run at startup. Modifying the .bashrc, .bash_profile, etc that route got me no where. Then I tried cron jobs, no luck. Then I've been pulling my hair trying to use the launchd function. I've made a launch daemon, which is allegedly the root functions, but that's no luck either. As a last try, I even tried Automator with no luck.

The file I want to run as root is: "/Users/CURRENT_USER/Dev/my_script.sh"

Here is what I have in my LaunchDaemons folder:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;com.startup.script&lt;/string&gt;
    &lt;key&gt;LaunchOnlyOnce&lt;/key&gt;
    &lt;true/&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;sh&lt;/string&gt;
        &lt;string&gt;-c&lt;/string&gt;
        &lt;string&gt;/Users/CURRENT_USER/Dev/my_script.sh&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;RunAtLoad&lt;/key&gt;
    &lt;true/&gt;
    &lt;key&gt;UserName&lt;/key&gt;
    &lt;string&gt;root&lt;/string&gt;
&lt;/dict&gt;
&lt;/plist&gt;
A ~/Library/LaunchDaemons doesn't exist. A launch daemon in /Library/LaunchDaemons is already executed with root privileges so you may omit the UserName part.

So put your shell script my_script.sh in /usr/local/bin/ or in /usr/bin/ (adjust the path in the ProgramArguments array if you use the latter), make it executable with sudo chmod +x ... and owned by root:wheel with sudo chown root:wheel .... /usr/bin is recommended if brew is installed.

Modify your current plist to:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;com.startup.script&lt;/string&gt;
    &lt;key&gt;LaunchOnlyOnce&lt;/key&gt;
    &lt;true/&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;sh&lt;/string&gt;
        &lt;string&gt;-c&lt;/string&gt;
        &lt;string&gt;/usr/local/bin/my_script.sh&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;RunAtLoad&lt;/key&gt;
    &lt;true/&gt;
&lt;/dict&gt;
&lt;/plist&gt;


Save the launch daemon as com.startup.script.plist in /Library/LaunchDaemons/ and owned by root:wheel.

Launch it with:

sudo launchctl load /Library/LaunchDaemons/com.startup.script.plist