I've been tagged [This link opens in a new window]

Mount a network share automatically in Mac OS X

I love OS X, I haven't once looked back from my switching days, but I still get a little frustrated by the way OS X handles network shares. In OS X all network shares feel as if they are exactly that, shares, and not part of your Mac. Whereas Windows felt different, it felt like the share was part of your PC and it was always there (on boot, after waking etc) and that made life a lot easier.

Leopard has improved on its sharing abilities (with other Mac's or Windows PC's) in the way all network computers are seen on the sidebar, but this doesn't mean they are connected! For example, you may see your Windows PC on the left, but you have to physically click and connect for the share to be mounted to your Mac, this is frustrating, especially when I just want to boot my Mac and open Dreamweaver straight up and get coding.

Before you actually mount the share, if I where to start up Dreamweaver, I wouldn't see my Windows 2003 server in my files list, so I would have to go and mount this drive then go back to Dreamweaver. You can add the mount to your login items, but then you get the folder popping up every time you boot (regardless of the "hide" checkbox being checked or not). So I done some research and found a great way to mount your shares on boot without interrupting you! This method works in OS X Tiger and Leopard.

The way to do this is via AppleScript, with AppleScript you can write simple functions for OS X to understand, and even save them as Applications (.app) which I will show you here.

So to mount a share automatically when you boot in to OS X, open up the Script Editor.app (it's in Applications > AppleScript). Now in this window you can start entering your AppleScript. Below is a snippet of my "mountnetwork.scpt" file:

tell application "Finder"
activate

try
mount volume "cifs://WORKGROUP;Steve@WRIGHT/WEBSITES" end try

end tell

What the above is doing is telling "Finder" to mount the Windows volume (cifs://). So my example above is mounting my Windows share named "WEBSITES" which is on my server called "WRIGHT" using a username of "Steve". I am also telling OS X that it is in a workgroup called "WORKGROUP".

Once you have entered the details for your server, press the "Compile" button, as long as you get no errors you are ready to save this as an Application. Before saving it as an Application though, save it as a script first so you can return to it in the future if you want to add more shares.

To save the script as an Application go to File > Save as and find the place you want to save it. Enter a name for it, and in the "File Format" drop-down select "application". Before pressing Save, it is very important you ensure you ONLY have the "Run Only" checkbox ticked, uncheck all the others. Without doing this, you will get the "Run" or "Quit" popup every time you run the Application.

Once this has been saved, double click the .app and see if it mounts your share(s). If this was successful, simply drag the app into you Login Items and check the "Hide" box and you shares will mount on boot every time!

If you are on OS X Tiger, when your Mac sleeps (if you allow that) the share(s) may disappear when your Mac wakes up, to fix this install the SleepWatcher app, with this you can tell OS X to do anything after it wakes from a sleep. Fortunately, Leopard doesn't have this problem.

  • Del.icio.us [This link opens in a new window]
  • Digg [This link opens in a new window]
  • Technorati [This link opens in a new window]
  • Reddit [This link opens in a new window]
  • Stumble Upon [This link opens in a new window]
  • Furl [This link opens in a new window]