The most widely read post on this site is my 2012 post on scheduling tasks using launchd. But my knowledge of launchd is limited to my experience. In particular, I was mistaken about how to set up a task when your computer has multiple accounts.
(For many years, my wife and I shared an account, mostly because it’s still so difficult to switch between accounts and properly share files. But now, with iPhones and iCloud, it’s even more painful to share an account, so we finally split things up.)
In my post, I wrote:
If you have multiple users and need something to run no matter who is logged in, you should look into putting it in
/Library/LaunchAgents
.
But this isn’t quite right. For system-wide jobs, there are two
folders that can
contain your Launch Agent plists: /Library/LaunchAgents
and
/Library/LaunchDaemons
.
The difference is that system-wide Launch Agents run exactly like per-user Launch Agents, except that they run once for each user. If you have two users logged in, the system will run two instances of the Launch Agent job. Each job will run with that user’s permissions. (This may actually cause problems. For example, if you need to write to a file, you must use a different file for each user or use a file that is world-writable.)
Launch Daemons, on the other hand, spawn a single instance, regardless of who is
or is not logged in. By default, these run with root permissions (be careful!),
although you can (and almost always should) customize this with the UserName
key.