I’ve been writing some software for the Mac to run under launchd. My program is a background utility that needs access to the user’s keychain to do part of its work. The program ran fine during the development process when started from the shell, but as soon as I hooked it up to launchd, it could no longer find the password in the keychain. Many, many, many hours later, I figured it out.

Launchd has several “modes” that it can launch an “agent” in. I was telling launchd to run my program in the wrong mode. I had to add a  LimitLoadToSessionType key set to Aqua to the configuration file that I fed to launchctl and call launchctl using “-S Aqua” option. There was much rejoicing! Before the program was trying to read the default system keychain, but with the “Aqua” setting, it used the user’s default, which is what I wanted.

If you’re using launchd, this little doc is your friend!

Bookmark and Share