title: LaunchAgent run bash script as root
body: <pre><code>&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.nords.locationchanger&lt;/string&gt;
      &lt;key&gt;ProgramArguments&lt;/key&gt;
      &lt;array&gt;
          &lt;string&gt;/usr/local/bin/locationChanger.sh&lt;/string&gt;
      &lt;/array&gt;
      &lt;key&gt;WatchPaths&lt;/key&gt;
      &lt;array&gt;
          &lt;string&gt;/Library/Preferences/SystemConfiguration&lt;/string&gt;
      &lt;/array&gt;
  &lt;/dict&gt;
  &lt;/plist&gt;
  </code></pre>
  
  <p>The LaunchAgent is in /Library/LaunchAgents</p>
  
  <p>How can I make locationChanger.sh run as root?
  The script throws erros saying it needs to be root. If I add sudo in front of the lines that need root it throws an error stating a password is needed.</p>
  
  <p>The lines in the bash script that need root are "route add" and route delete"</p>
  
  <pre><code>#!/bin/bash
  
  exec 2&gt; &gt;(logger -t NETWORKSCRIPT)
  
  location=$(networksetup -getcurrentlocation)
  internalName="Internal"
  
  if [ $location == $internalName ];
  then
      echo "Internal Network!"
      logger -i "NETWORKSCRIPT CHANGE: Internal network, setting up custom routs and proxy stuff"
      git config --global http.proxy http://webproxysea.██████.net:8181
      route add -host 54.80.220.236 192.168.15.1
  else
      echo "External Network!"
      logger -i "NETWORKSCRIPT CHANGE: $location network, removing custom stuff!"
      git config --global --unset http.proxy
      route delete -host 54.80.220.236 192.168.15.1
  fi
  </code></pre>