View RSS Feed

seawolf

Script to Map Network Shares on OSX (AFP or SMB)

Rate this Entry
by , 30th June 2014 at 10:17 AM (1867 Views)
I have tested mapping shares with Profiles and determined that it wasn't 100% reliable, and not as powerful as I liked. I decided to use an AppleScript to map the network shares, which is saved as an app with a nice icon and run at login. It can also be run if the shares disconnect while the user is logged in, which happens quite often since so many of our teachers just close the lid and can go weeks or months without actually logging in to their account on the network (sigh).

The script that I use is below and can be edited easily for use in any environment:

Code:
try
	set loggedInUser to do shell script "whoami"
	
	set accountType to do shell script "dscl . -read /Users/" & loggedInUser & " | grep UniqueID | cut -c 11-"
	
	set nodeName to do shell script "dscl . -read /Users/" & loggedInUser & " | awk '/^OriginalNodeName:/,/^Password:/' | head -2 | tail -1 | cut -c 2-"
	
	set ADGroups to do shell script "dscl " & quoted form of nodeName & " -read /Users/" & loggedInUser & " | awk '/^dsAttrTypeNative:memberOf:/,/^dsAttrTypeNative:msExchHomeServerName:/'"
	
	if accountType is less than 1000 then
		tell me to quit
	end if
	
	if ADGroups contains "AllStaff" then
		mount volume "smb://<servername>/Staff/" & loggedInUser & ";" & loggedInUser & ":password"
		mount volume "smb://<servername>/MediaLibrary/" & loggedInUser & ";" & loggedInUser & ":password"
		mount volume "smb://<servername>/Scans/" & loggedInUser & ";" & loggedInUser & ":password"
	end if
	
	if ADGroups contains "AllTeachers" then
		mount volume "smb://<servername>/Curriculum_Archives/" & loggedInUser & ";" & loggedInUser & ":password"
		mount volume "smb://<servername>/IWB/" & loggedInUser & ";" & loggedInUser & ":password"
		mount volume "smb://<servername>/Reports/" & loggedInUser & ";" & loggedInUser & ":password"
		mount volume "smb://<servername>/Teachers/" & loggedInUser & ";" & loggedInUser & ":password"
	end if
	
	if ADGroups contains "IWB_Group" then
		mount volume "smb://<servername>/Teachers/" & loggedInUser & ";" & loggedInUser & ":password"
		mount volume "smb://<servername>/IWB/" & loggedInUser & ";" & loggedInUser & ":password"
		mount volume "smb://<servername>/Scans/" & loggedInUser & ";" & loggedInUser & ":password"
	end if
	
	if ADGroups contains "OHS" then
		mount volume "smb://<servername>/OHS/" & loggedInUser & ";" & loggedInUser & ":password"
	end if
	
	if ADGroups contains "AdminDepartment" then
		mount volume "smb://<servername>/Admin/" & loggedInUser & ";" & loggedInUser & ":password"
	end if
	
	if ADGroups contains "FinanceStaff" then
		mount volume "smb://<servername>/Finance/" & loggedInUser & ";" & loggedInUser & ":password"
	end if
	
	if ADGroups contains "PrimaryStudents" then
		mount volume "smb://<servername>/Primary/" & loggedInUser & ";" & loggedInUser & ":password"
	end if
	
	if ADGroups contains "PrimaryTeachers" then
		mount volume "smb://<servername>/Primary/" & loggedInUser & ";" & loggedInUser & ":password"
	end if
	
	if ADGroups contains "ICT" then
		mount volume "smb://<servername>/Installers/" & loggedInUser & ";" & loggedInUser & ":password"
		mount volume "smb://<servername>/ICT/" & loggedInUser & ";" & loggedInUser & ":password"
		mount volume "smb://<servername>/Archives/" & loggedInUser & ";" & loggedInUser & ":password"
		mount volume "smb://<servername>/ISO-Library/" & loggedInUser & ";" & loggedInUser & ":password"
	end if
	
	if ADGroups contains "VCAL" then
		mount volume "smb://<servername>/VCAL/" & loggedInUser & ";" & loggedInUser & ":password"
	end if
	
	if ADGroups contains "MediaStudents" then
		mount volume "smb://<servername>/VCD/" & loggedInUser & ";" & loggedInUser & ":password"
	end if
	
	if ADGroups contains "MediaTeachers" then
		mount volume "smb://<servername>/VCD/" & loggedInUser & ";" & loggedInUser & ":password"
	end if
	
on error error_message number error_number
	display alert ("One or more NetworkDrivefailedtoinstall.
Pleasereportthiserrortothe ICT Help Desk.

") ¬
		message error_message ¬
		¬
		& (" Error number ") & error_number & "."
end try
p.s. you can also use "afp" rather than "smb" shares in the script. We mostly use AFP, but I edited it as I suspect many on here will just be using SMB.
Categories
Uncategorized

Comments

  1. seawolf's Avatar
    Quote Originally Posted by furby
    I can't get this to work, is it just AD groups and "server name' that needs changing?
    The share names and paths need to be changed as well. Be careful if you cut some parts of the script out that you don't mismatch the open/close brackets, etc.

    This script will quit without doing anything if the user is logged into a local account. It only attempts to mount the shares if a network user is logged on.
    Updated 2nd July 2014 at 05:21 PM by seawolf

Trackbacks

Total Trackbacks 0
Trackback URL: