Run script on networked user login
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.