I am having a problem getting my LaunchAgent to run as a normal (not-root) user. Everything I've read implies this should be the default behavior. The expectation is that if you put the plist in /Library/LaunchAgents then when it loads it loads for the user, as the user, at the users login.
What I am finding however is that if you run launchctl with sudo ('sudo launchctl load /Library/LaunchAgents/myagent.plist') then the process starts in the user session as root. This means 'ps u -ax' shows the process running as 'root', and also that files created by the process are owned by root:staff
I have tried googling about this and have found a ton of posts like someone wants their agent to have root access (which IMO is "wrong") and they are making all these forum posts about "how can I give it root" and everyone is replying to explain "it doesn't get root, its a user agent"... That is what I expect, however I am having the opposite problem, I don't want this agent to have root access, it shouldn't have it, yet it does have it.
If the answer is "you just simply can't run launchctl load with sudo or this happens", I have not been able to find that documented anywhere. And if that is the case then how do I do a launchctl unload/load on the Agent from a Daemon which should have root access, which is something I need to do for the product to update itself?
EDIT: Here is an example of a commonly linked post which makes it seem like this shouldn't even be an issue, makes it sound impossible for the Agent to run as root even if you wanted it to... https://superuser.com/a/36173/603140