Mac mapping drive script

New Contributor III

Hi Everyone

Do anyone have best mapping drive script that could share with me. I would like script that do similar like windows mapping script.
that is when a user loggin (using windows AD account) Mac then it auto mount that user home drive and staff share
Please forgive me to ask a basic question because i am a newbie to the Mac world.



Release Candidate Programs Tester

I've an applescript app that maps drives & printers based on group membership.

Valued Contributor

I use the drive mapping script from JAMF and an Extension Attribute + Smart Folder to map them to an AD group.

New Contributor

Hi Matt, where do I find the JAMF mapping script and Extension Attribute?

New Contributor II

Jeff, I believe Matt's referring to the script in the Resource Kit. I've used a variant of that with good effect.


Contributor III

Here's ours:

smbhome="$(dscl '/Active Directory/All Domains' -read /Users/$currentuser SMBHome)" 
if [ $? != "0" ] ; then 
        echo could not get smb home.  Offline? 

smbhome=$(echo $smbhome|awk -F ': ' '{printf $2}'|perl -p -e 's/([^\:A-Za-z0-9-._~])/sprintf("%%%02X", ord($1))/seg'|sed -e 's/\///g') 

if [ "$smbhome" == '' ] ; then 
        echo could not get smb home.  Not defined for user $currentuser? 
out='<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ""> 
<plist version="1.0"> 
echo $out > ~/Q-Drive.inetloc 

/Library/Application Support/Q-Drive/seticon -d /Library/Application Support/Q-Drive/Q-drive.icns /Users/$USER/Q-Drive.inetloc

/Library/Application Support/Q-Drive/dockutil --add ~/Q-Drive.inetloc

mkdir /Volumes/$currentuser
mount_smbfs $smbhome /Volumes/$currentuser

exit 0

A bit of an explanation is needed for a bit of this. What this script does is check Active Directory for their SMB home folder. Once obtained, it writes out an .inetloc shortcut file and places it into the user's local home directory.

It then uses a program called "seticon" that I found, part of a larger set of tools called "osxiconutils," to change the icon for the file, as we wanted the shortcut to be easily identifiable. (Seticon is very old. It required recompiling to even work on current systems, and even then it throws errors in the console about deprecated methods... but it still works as of 10.6.8.)

It then uses another old utility, dockutil, to add the item to the dock.

Finally (phew!) it mounts the drive using mount_smbfs.

This script has adequately handled even odd Windows home folders that have unusual characters or spaces in them. I make no claims that it will handle every instance, but so far, it does pretty well.

New Contributor III

Cool thank you all

New Contributor

Sorry to reopen.

But why is it accepted that a MAC OS X 10.7.4 through to our latest 10.10.3 can't automount the network Home Directory?
I am on the phone to Apple now but I don't hold much help.
When I visit the Directory Utility under users and look at the Local/Default I note the entry OriginalHomeDirectory is <home_dir><url>smb://servername/level1/</url><path>level2/level3/userhome/</path><home_dir>
but in the Active Directory the entry HomeDirectory is
The issue is that the regular user doesn't have permission to //servername/path1/ but they do
to servername/level1/level2/level3/userhome/ I know the network admins are loath to change the permission to give all users access to the higher directory path but that is the only way to make it work on the apple (without scripts are mods on the mac).
If this worked then having a script to create the link is unnessisary.