Network Share Mounting at Startup

I wrote this based of a few posts here to mount a selection of network shares at startup. Just change the defined variables at the top of the script to be relevant to your network, you can add as many shares as you want in the NetworkShares array. Then add the script to your startup items.


set NetworkShares to {"Share01", "Share02", "Share03"}
set ServerPath to "afp://my.lan/"
set UserName to "user"
set UserPassword to "password"
set mountedVolumes to list disks

repeat with ShareName in NetworkShares
	set SharePath to ServerPath & ShareName
	log ShareName
	
	if mountedVolumes does not contain ShareName then
		mount volume SharePath as user name UserName with password UserPassword
		log SharePath & " has been mounted as user " & UserName
	else
		log SharePath & " is already mounted"
	end if
end repeat

if you don’t want the username and password in the script, as long as you’ve connected to the server once and stored the details in your keychain you can use the script like this…


set NetworkShares to {"Share01", "Share02", "Share03"}
set ServerPath to "afp://my.lan/"
set mountedVolumes to list disks

repeat with ShareName in NetworkShares
	set SharePath to ServerPath & ShareName
	log ShareName
	
	if mountedVolumes does not contain ShareName then
		mount volume SharePath
		log SharePath & " has been mounted"
	else
		log SharePath & " is already mounted"
	end if
end repeat

You can obviously remove the log lines if you don’t want to have them in your script too.

Thought I’d share it and hope it’s of use to some people,

/ Hami