The computer lab is running 10.8. I would like to run a script when networked users login. As far as I can tell my choices are:

launchd agents - Not meant for this. On the launchd.plist man page it says "An agent launched by launchd SHOULD NOT do the following as a part of their startup initialization: Setup the working directory." That's basically what my script does.

login items - A number of posts indicate that they worked in 10.7 but don't work in 10.8

login hooks - This works but the "Customizing Login and Logout" on developer.apple.com says "There are numerous reasons to avoid using login and logout scripts: Login and logout scripts are a deprecated technology."

I don't want to use something that won't work tomorrow. I would like to do this the "right way" if there is one. Please advise. Thanks.

  • What does the script need to do as this is normally a launchd agent - if setting up the working directory what applications use this and how as many will ignore this and won't know how this is set. (This is the reason why launchd should not set the cwd because other apps can't see it)
    – mmmmmm
    Apr 1, 2013 at 18:27

1 Answer 1


Setting the Working Directory for a Script

You should use a launchd agent job placed in the /Library/LaunchAgents folder.

The advice you mention, quoted below, is aimed at the executable or script being launched. You should let launchd manage the working directory for you.

A daemon or agent launched by launchd SHOULD NOT do the following as a part of their startup initialization:

  • Setup the user ID or group ID.
  • Setup the working directory.
  • chroot(2)
  • setsid(2)
  • Close "stray" file descriptors.
  • Change stdio(3) to /dev/null.
  • Setup resource limits with setrusage(2).
  • Setup priority with setpriority(2).
  • Ignore the SIGTERM signal.

The launchd job ticket is responsible for requesting the desired working directory; use the WorkingDirectory key to set the directory. The directory will be automatically set before your executable or script is launched.

A full description of the available keys in a launchd job ticket are available in the launchd.plist(5) manual page.

Setting the Working Directory for the User

Consider providing a modified ~/.bashrc or other shell login script to provide a known current working directly.

  • Right. Unfortunately the script being launched makes an alias on the user's desktop. I believe that is why it didn't work, because it was setting up the working directory. I read the man pages, wrote the plist, troubleshot this with an expert in the Apple forum. It didn't work. Apr 1, 2013 at 21:00
  • @SlimVolume please can you append the launchd job ticket and script as part of your question. Apr 2, 2013 at 7:35
  • 1
    Thanks! Previously I had tried to use launchd to create folders that weren't previously there. This time, after you suggested launchd as the "right way" to do this, I started almost from scratch doing something similar. I got it to work. Apr 2, 2013 at 20:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .