AppleScript to mount Samba servers

Our office is mainly a Windows shop, both employee computers and file servers. But being one of the few people who use a mac it’s always a pain to mount the necessary networked drives on a daily basis. So I took some time the other day to write an AppleScript that runs on login to mount all the network drives I need to use throughout the day. It also checks my IP address to see if I am in the office or connected through VPN before trying to mount the drives.

Here is the script. I have masked out the ip addresses but you should be able to get the idea to set this up to use it for your needs.

set TheAddress to (do shell script "curl -f http://checkip.dyndns.org | awk '{print substr($6,1,13)}'")
 
if TheAddress is equal to "xxx.xxx.xx.xx" then
    --display dialog "Your OFFICE IP is : " default answer (TheAddress)
    mount_drives()
else if TheAddress is equal to "xxx.xxx.xx.xx" then
    --display dialog "Your VPN IP is : " default answer (TheAddress)
    mount_drives()
else
    display dialog "You aren't at work"
end if
 
on mount_drives()
    mount volume "smb://xx.x.x.x/projects"
    mount volume "smb://x.x.x.x/dev"
end mount_drives

To set this to run on login go to System Preferences>Accounts>and Login Items under your account. From there you can add the script to the list.

Continue reading » · Rating: · Written on: 04-22-09 · No Comments »