launchd maintains a separate list of items for each user session ("launch agents"), and one for the system context ("launch daemons"). When you run launchctl load
as root, the item is loaded into the system list (i.e. as a launch daemon instead of an agent) no matter where the file is located. What you need to do depends on exactly what you're trying to accomplish:
If you're trying to get the item to load as a launch agent into future user sessions (i.e. for the next time you log in), just put it in /Library/LaunchAgents, set the permissions properly, then sit back and relax. When a user logs in it scans that directory and loads whatever it finds.
If you're trying to get the item to load into an existing login session, you need to run
launchctl load
in that session. Exactly what that means and how you do it is complicated, and may depend on which version of OS X you're running (Apple keeps changing the launchd architecture...). At least in older versions of OS X, you'd have to find the process ID of some process running in the session you're targeting, and run something like:sudo launchctl bsexec $PIDInTargetSession sudo -u $TargetUsername launchctl load /Library/LaunchAgents/youritem.plist
Explanation: the first
sudo
switches to root, thenlaunchctl bsexec $PIDInTargetSession
switches to the target sessions's mach bootstrap context (I said it was complicated), thensudo -u $TargetUsername
switches UID from root to the target user, then finallylaunchctl load /Library/LaunchAgents/youritem.plist
loads the agent in that session.
If that doesn't do it, check this message for some alternatives.