Why does my LaunchAgent return ROOT as the user? I have a plist in the /Library/LaunchAgent folder (this should run as "logged in user", if I understand correctly but it seems to be running as root). It launches a .sh bash script.

&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.user.uloginscript&lt;/string&gt;
        &lt;key&gt;Program&lt;/key&gt;
        &lt;string&gt;/Library/TestArea/netcall.sh&lt;/string&gt;
        &lt;/dict&gt;
&lt;/plist&gt;


The script, for troubleshooting, contains the following lines:

#!/bin/bash
curUser=$(id -u -n)
osascript -e 'tell app "Finder" to display dialog "'$curUser'"' 


OR

#!/bin/bash
curUser=$(USER)
osascript -e 'tell app "Finder" to display dialog "'$curUser'"' 


The message box result is always:


  root


This means that any scripting that I am trying to do has issues. Can anyone shed any light on why this is happening. The script runs on each login, runs before the user's desktop appears (the message appears on the login screen).

Curiously, if I use the following code:

#!/bin/bash
osascript -e 'tell app "Finder" to display dialog "'$1'"' 


It returns the correct username. It seems that the script is running as root, but has passed the parameter of the logged in user (note that the plist has no parameters).

Running Mavericks 10.9.5
A LoginHook was present. Loginhooks run as root and was calling the same file.
The following command removed the hook:

sudo defaults delete com.apple.loginwindow LoginHook


Thank you all for your time, and apologies for the wild goose chase. I knew it wasn't correct.