Mounting Windows network drives at login (OS X tip)


Windows users will be familiar with the ability to map network drives and to have those drives connect automatically when they next login to their PC. For all its ease-of-use, Mac OS X seems to lack that ‘Reconnect at logon‘ functionality, forcing users to come up with an alternative.

As a new Mac user I hunted around for a solution, and something that didn’t cost any money or require a certificate in programming to implement. The most common solution by far in the various Mac forums is to manually connect to the chosen network drive (using the Go – Connect to server option in Finder), and to then drag the resulting volume icon into your Login Items in the System Preferences – Account Settings. That’s all well and good, but the only problem with that approach is that a window will automatically open on your desktop for each connected drive when you logon.

I eventually found a slightly slicker way of doing this which isn’t too complicated, requiring you to simply create a short script. It works as follows:

1. Go to your applications folder and open the folder called AppleScript.

2. Run the Script Editor. A small window will appear, showing a blank page.

3. Copy the following text into the top half of the window…

tell application “Finder”
try
mount volume “smb://<username>:<pwd>@<servername_or_address>/<sharename>

on error


display dialog “Unable to mount network volume.” & return & return & ¬
“The network, target server or share may be unavailable.” & return & return & ¬
“Click OK to continue.” buttons {“Okay”} default button 1
end try
end tell

4. New edit the above text as follows:

  1. Replace <username> and <pwd> with the required username and password if necessary. If it’s a public share then just replace them with something like ‘Guest’ and ‘null’ as they’ll get ignored.
  2. Replace <servername_or_address> with the name of your server/PC (if you use DNS) or simply the IP address of the machine (if you don’t know what DNS is)!
  3. Finally, replace <sharename> with the name of the Windows share you wanto to connect to. Equally you can use the dollar symbol to connect to hidden shares, e.g. F$ for the hidden administrative share of the F: drive on a Windows server.

5. The next step is to compile your script to check for errors, so click on the Compile button to check all the syntax is OK.

6. Now you need to save the script as an executable application. Click File – Save As and make sure you’re saving it as an ‘Application’. Give the saved file a meaningful name and choose where to save it. I put all my scripts in a folder called ‘Scripts’ in my documents folder.

7. The final step is to drag the icon of the script you’ve just created into the Login Items list for your account (in System Preferences / Accounts).

That’s it! Next time you login a window will pop up asking if you want to run the script. Just click on run or cancel (useful if you’re a laptop user away from your network). If you click ‘run’ the the script will run in the background and will automatically connect to your network drive. If you want to connect to multiple network drives, then either create multiple scripts, or better still simply repeat the ‘try… end try’ section the required number of times, specifying a different network drive to connect to in each case.

The one word of caution is that if you need a username and password to connect to the network share, then they’ll be stored in your script as plain text, so use with caution…

Hope this helps.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: