Since writing my previous post on this subject I have found a much better way of doing this, and as a bonus it works as a far more generalised login script than just mapping drives.
Instead of using launchd this approach uses an OSX feature to automatically run applications at login and logout. I found the basic technique at MacEnterprise.org so please check out the original article describing how to to set up the base system and then see below for how to set up drive mappings
http://www.macenterprise.org/articles/runningitemsatlogin
An entry is added to the AutoLaunchedApplicationDictionary of the global loginwindow preference file. This calls an application launcher during logon for all users which then executes all scripts in a given directory.
On logout, the loginwindow LogoutHook is used to call a similar launcher to remove any drive mappings or other clean up that should be performed during logoff.
The launcher applications are just scripts that are bundled into two OS X “apps”, one for running the login scripts and one to run the logout ones. These applications and scripts are located in the following directories
/Library/Vuzzlevuzz/LoginLauncher.app
/Library/Vuzzlevuzz/LogoutLauncher.app
/Library/Vuzzlevuzz/LoginItems
- place scripts to be run at login here
/Library/Vuzzlevuzz/LogoutItems
- place scripts to be run at logout here
The two basic scripts that should be added to the relevant folders for connecting to network shares are:
/Library/Vuzzlevuzz/LoginItems/mapVolumes.sh
/usr/bin/osascript <<-EOT
try
mount volume “smb://servername/share”
end try
EOT
/Library/Vuzzlevuzz/LogoutItems/unmapVolumes.sh
/usr/bin/osascript <<-EOT
tell application “Finder” to eject “sharename”
EOT
DO NOT EDIT THESE SCRIPTS ON WINDOWS MACHINES!
Windows and Macs use different file formats, if these files are edited on a Windows machine they will not work – all editing or creation of new scripts must be done on a Mac.
These instructions assume that the relevant files (the Vuzzlevuzz directory and below) have been copied to the desktop of the machine you are installing on and that you are logged in as a user with administrative privileges.
Open a terminal (Finder... Utilities... Terminal) and enter the following commands (Note: each number represents one line to enter at the terminal, ignore any other line breaks)
1. sudo mkdir /Library/Vuzzlevuzz
2. sudo cp –r ~/Desktop/Vuzzlevuzz/* /Library/Vuzzlevuzz
3. sudo chmod a+x /Library/Vuzzlevuzz/LoginLauncher.app
4. sudo chmod a+x /Library/Vuzzlevuzz/LogoutLauncher.app
5. sudo chmod a+x /Library/Vuzzlevuzz/LoginItems/*
6. sudo chmod a+x /Library/Vuzzlevuzz/LogoutItems/*
7. sudo defaults write /Library/Preferences/loginwindow '{ AutoLaunchedApplicationDictionary = ({Hide = 1; Path = "/Library/Vuzzlevuzz/LoginLauncher.app"; });}'
8. sudo defaults write com.apple.loginwindow LogoutHook /Library/Vuzzlevuzz/LogoutLauncher.app
References:
http://www.macenterprise.org/articles/runningitemsatlogin