Automating Mac OS X notebooks


I just found this pretty neat script for Mac OS X to auto-mount network filesystems, according to your IP. Nothing fancy, but as most of the Mac users are not familiar with scripting, it’s a nice thing to try out 😉

The script checks wether you are in the right network by determining your IP (which therefore needs to be a fixed IP, provided by a DHCP server/router). You could of course also use wild cards, but I guess this is the better solution (ideal if it is something fancy, not that common, so no 192.168.0.x) – but you’ll figure something.

set myip to do shell script “ifconfig | grep ‘broadcast’ | awk ‘{print $6}’”
if myip = “10.168.1.255″ then
     mount volume “smb://workgroup;username:password@10.168.1.254/path/”
else
     display dialog “Not able to connect server” buttons {”ok”} default button “ok”
end if

The example uses 10.168.1.255 as client address in line 2, so this is what you’ll need to change. The other line that needs adjustment is line 3. You of course change “workgroup” with the name of your workgroup, “username” and “password” accordingly, and after the @ there’s the IP of your server, and the path to that share that you want to mount.

That’s all there is, no magic. If the connection for what so ever reason does not work, you’ll get a dialog window, saying “Not able to connect server” that you can click away with “ok”.

Advertisements