How to: Mount a network drive in Mac OS at startup
One of the neat things about Mac OS is how easy it is to create network shares, and how quick and reliable they are. Once you've got the dang things mounted, that is. Therein lies the annoyance, there isn't a built-in feature for automounting them. Luckily, it's quite easy to set up with AppleScript.
Having finally got my Airport Extreme working, I've moved my 2TB Drobo directly onto the network, rather than having to have my Mac Mini running all the time to get at my media.
I still needed to be able to get to the files from my Mac Mini, and because it was running as a media centre, I couldn't be doing with fiddling about browsing to the share before I could load my media applications. After a bit of fiddling (and some Googling), I set up an AppleScript to do load the drive on startup. And here's how you can do it too:
1. Get a path to the drive
If we're going to load a drive, we need to know where it is. You can do this by mounting it manually, then Command-Clicking the volume on the desktop and selecting "Get Info".
Copy the value for "Server" (shown highlighted), this is the path we'll need.
As a side note, I name all my hardware after Scooby Doo characters. The Drobo volume is called Freddy. Unfortunately, this naming convention only allows me to have five pieces of hardware on my network at once. I'll be damned if I'm calling anything Scrappy.
2. Create an AppleScript application to mount the drive
Load up the AppleScript Editor (usually under Applications/Utilities) and enter the following:
tell application "Finder" try mount volume "<PATH>" end try end tell
Where <PATH> is the path you copied in step 1.
So this script will run whenever you double-click it (instead of opening the editor again), be sure to save it as an Application (note the "File Format" option below).
So let's give that a try. Eject your networked Volume and double-click on the script application you've just created. The volume should re-appear, as if by magic (if Clarke's quote is accurate). We're nearly there!
3. Add the script to your Login Items
Open the Accounts dialog in System Preferences. Select the Login Items tab and authorize yourself for changes by clicking the lock icon in the bottom left hand corner. Once you've done that, click the plus button under the login items list and select the application you created. It should now appear in the list:
Fingers crossed, your network share should be mounted every single time you log in. If you feel like it, you can do the same for other users too.
But <My Favourite Application> still doesn't work!
In my case, I set up Dropbox on the Mini so it's files were all on the Drobo. This way I had an extra local backup of my most important files, and visitors could get access (if I let them) without having to set up additional shares. But unfortunately, it didn't work!
Every time my Mac Mini started up, I got a handy and surprisingly verbose error message from Dropbox headed "Dropbox Folder Missing" telling me my Dropbox folder had been moved or deleted. I was a little perplexed by this, as I could clearly see the volume on my desktop.
As it turns out, because my automount script and Dropbox were both configured as Login Items, they were starting in parallel, so when Dropbox looked for the folder, it still wasn't accessible. That being the case, the fix was relatively simple:
4. Stop your application from launching at startup
Dropbox has a preference for just that, as do many applications. Make sure this is turned off, and for safety, that the application doesn't appear in your Login Items (as in step 3).
5. Launch the application with your automount script
Edit the script you created in step 2, adding the following:
tell application "Dropbox" activate end tell
These lines will start Dropbox. As they run after the rest of the script, Dropbox won't start up until after the volume it needs has been mounted. You could add calls for multiple applications here. This won't necessarily work for all applications, but it's a good start.
So there you go. Not the easiest fix, I'll admit, but it'll hold us until Apple put in a decent automount option.