Re: LaunchDaemon to run as a particular user

Michael Babin <[email protected]> Tue, 22 Nov 2011 07:31:55 -0600
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
On Nov 21, 2011, at 11:15 PM, Nathan Sims wrote:

> I need to have a background daemon process that the system runs under =
my user automatically, 24/7, even when no one is logged in to the =
machine.=20
>=20
> I created a plist and placed it in /Library/LaunchDaemons, and the =
system loads it up, but it runs as root, not my user. I've seen this =
done before by adding a certain tag in the plist file (the name of which =
I forget), but after googling around for a while I still haven't =
identified which tag it is. (I know a launch agent runs as the user, but =
only when the user logs in, which is why I need it to be a daemon.)=20
>=20
> Does anyone know of the tag, or is there another way to do this?

I think the one you are looking for is:

UserName <string>
     This optional key specifies the user to run the job as. This key is =
only
     applicable when launchd is running as root.

See the man page for launchd.plist(5), particularly the section "XML =
PROPERTY LIST KEYS".