Mac mapping drive script

Nguyen
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.

Cheers

7 REPLIES 7

bentoms
Release Candidate Programs Tester

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

http://macmule.com/2011/09/08/how-to-map-drives-printers-based-on-ad-group-membership-on-osx/

Matt
Valued Contributor

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

krischelj
New Contributor

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

evarona
New Contributor II

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

Cheers.

georgecm12
Contributor III

Here's ours:

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

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? 
        exit 
fi 
out='<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
        <key>URL</key> 
        <string>smb:'$smbhome'</string> 
</dict> 
</plist>' 
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.

Nguyen
New Contributor III

Cool thank you all

queenwood
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
<home_dir><url>smb://servername/level1/level2/level3/userhome</url><path>/</path><home_dir>
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.