Mounting User Home Folders on Login

Updates here.


I’ve hacked away at this problem a couple of times since I’ve been at this org, but gave up each time, usually because something more important came up. But yesterday I decided to try again.
A bit of Googling (and bugging my friends), landed me a post called “HOW TO: MAP DRIVES & PRINTERS BASED ON AD GROUP MEMBERSHIP ON OSX” on

If you read my absurd “About Me”, you already know to expect frequent references to other blogs, as illustrated above.

This particular script actually does more than I’m interested in at the moment, so I cut it down a bit first.

Get logged in users username? Check.

Get the Users account UniqueID? Check.

Get the nodeName from the Users account? Check.

Get the Users group membership from AD ? Nope. Don’t need that.

Get the Users AD Home Folder? Check.

Mount Drives? Check.

Mount shares based on groups? No, thanks.

Printers? Nope, not that either.

My bastardized version of macmule’s script looked like this:

Bring On The Errors

TBH, I expected errors. Mostly because nothing I ever do with AD goes smoothly. So I was pleasantly surprised to only have one. I ended up with a blank value for ADHome. The command to mount looked something like this

mount volume smb:

To make a long story short, the script was using grep to find a value for SMBHome. Except nothing in my AD profile had that string AND nothing in my profile returned what I wanted. Eventually I realized that if I looked locally I could find the string NFSHomeDirectory with the information I wanted.

set ADHome to do shell script "dscl " & quoted form of nodeName & " -read /Users/" & loggedInUser & "| grep SMBHome: | cut -c 10- | sed 's/\\\\/\\//g' "

became  set ADHome to do shell script "dscl . -read /Users/" & loggedInUser & "| grep NFSHomeDirectory: | cut -c 19-"

and, since this didn’t provide me any AD information,
mount volume "smb:" & ADHome became mount volume "smb://" & "domainname" & ADHome

*I had to put the // in because I’d pulled out the line that dealt with them in the original.

Wrapping Up

After that, I went back to the original post:

A quick plist,

goes in the LaunchAgents folder. Saved the script as an app and packaged the two together, and I was done. Woo!


TL:DR AD and I don’t often get along.


Leave a Reply

Your email address will not be published. Required fields are marked *