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?
thanks
Model: Macbook Pro
Browser: Firefox 2.0.0.9
Operating System: Mac OS X (10.5)
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
else
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
try
mount volume "smb://user:pass@IPaddress/" & SMBvolume
end try
end if
end if
end setStatus
on run
setStatus()
end run
on idle
setStatus()
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