Automatically mount shares based on location

Dec 27, '06 07:30:00AM

Contributed by: smanek

One thing that frequently bothered me about OS X was the lack of any way to automatically mount Windows file shares. At home, my DHCP server assigns me an IP of 10.0.x.x, and I want to mount my home shares, which include access to my media library, personal documents, etc. I also didn't know if I'd be connecting to my network via wifi or ethernet, so I would ideally like to check both. Well, some quick googling didn't really find an adequate solution, so I cobbled together my own.

First, we'll write an AppleScript to actually mount the Samba share. Start by running the Script Editor, and writing:

try
mount volume "smb://username:password@server_ip/share_name"
end try
Then, hit the Compile button. Assuming you got no errors, we're ready to save. Press File, Save As, and enter .mount as the filename (and make sure you are saving in your home directory). Choose Script as the file format, and then hit save. Now, we need a way to make this script run on boot/wakeup, if and only if we're on our home network. This requires an install of sleepwatcher, a great freeware utility.

Open the terminal, type nano -w ~/.wakeup and paste this text into the Terminal. As the script is written, it only mounts the volume if your computer's IP address's first two octets are 10.0.x.x. Feel free to modify to taste.

[robg adds: I haven't tested this one.]

Comments (7)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20061224140933809