Connect to smb drive whenever connect to certain wifi network

Hi I’m a newbie to applescript and have never really used applescript before. So any help or resources would be a huge help on how to get started.

What I’m trying to do is connect to a certain smb drive whenever I connect to my home wireless base station. I have OSX set where it will reconnect to my smb drive at startup, but if I lose my wireless connection or take my laptop out of the house and I can no longer connect to my smb drive then I have to manually connect to it again. I’d really like for whenever I connect to my home wifi network that it would automatically reconnect to the smb drive.

Can this be done? If so could someone point me in the right direction on how to start making this happen?


Model: Macbook Pro
Browser: Firefox
Operating System: Mac OS X (10.5)

Hi Evan,

you can do this with a stay open script like this,
it checks every 60 seconds the connection and mounts the volume, if necessary

property SMBvolume : "myVolume"
property homeSSID : "homeNet"
property idleTimeout : 60 -- seconds

on getLocation()
	set wiredIP to do shell script "ifconfig en0 | awk '/inet / {print $2}'"
	set {wirelessIP, ssid, conneted, wired, IPAddress} to {"", "", false, false, ""}
	if wiredIP is not "" then
		set IPAddress to wiredIP
		set connected to true
		set wired to true
		set wirelessIP to do shell script "ifconfig en1 | awk '/inet / {print $2}'"
		if wirelessIP is not "" then
			set IPAddress to wirelessIP
			set ssid to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk '/ SSID: / {print $2}'"
			set connected to true
			set wired to false
		end if
	end if
	return {connected:connected, wired:wired, IPAddress:IPAddress, ssid:ssid}
end getLocation

on setStatus()
	set currentLocation to my getLocation()
	if not connected of currentLocation then return false -- no net connection
	if not wired of currentLocation and ssid of currentLocation is homeSSID then
		if SMBvolume is not in (do shell script "ls /Volumes") then
				mount volume "smb://user:pass@IPaddress/" & SMBvolume
			end try
		end if
	end if
end setStatus

on run
end run

on idle
	return idleTimeout --update every n seconds
end idle


Thanks so much for your help. I had just one more question. Do I need to change some of the variables in the script? I know it’s probably a stupid question, but could you let me know which ones I should change?


You have to adjust the three property lines at the beginning (idleTimeout is the time interval in seconds the script will be restarted) and
the server parameters in the mount volume line

Hey Stefan…thanks for the info on the script. One more question. Does this script continuously run?

For example: If I am not connected to my home network will this script continue looking for my home network until I finally connect to it?

So if I set it to run at startup will it continue to run all the time?

Yes, if the script is saved as stay open, it runs periodically (depends on the variable idleTimeout)

the original script has a typo… in the getLocation() handler, “connected” is misspelled as “conneted”