24 Sep, 2008
How-To: Auto-Connect to Windows Shares from OS X
So you live in a Mac/PC hybrid environment and you regularly have to share files between them, right? Well, I don’t think it’s that uncommon, and there are several ways to tackle this problem, but I thought I would share with you my approach.
First we have to start out with a little bit of code for you, the tool of choice is Script Editor, which can be found in /Applications/Apple Script. First let’s start with a little code, er, script:
1: tell application "Finder"
2: mount volume "afp://UserName:Password@IPAddress/ShareName"
3: end tell
4:
5: tell application "Finder"
6: mount volume "smb://ComputerName;UserName:Password@ComputerName/ShareName"
7: end tell
Now, depending on your purpose, you may only need one of these two tell clauses. The first one is for connecting to shares on OS X systems, the second is for connecting to shares on Windows systems, which is the purpose for this post, so we will concentrate on that.
Fire up script editor and paste in lines 5-7. The tell application function tells the Finder application to perform the embedded commands. The command inside is mount volume which you use to, that’s right, mount a volume. In this case we will be using a random share named “mystuff” on a fictional PC called “mypc.” Your username will be “myusername” and your password is, can you guess? That’s right, “mypassword.”
The mount line in this instance would be:
mount volume “smb://mypc;myusername:mypassword@mypc/mystuff”
Pretty self explanatory really. Now the trick comes in, with this script edited, choose File, Save As…, give it an application, change the file format to “Application” and make sure “Run Only” is checked. and “Startup Screen” and “Stay Open” are unchecked.
Save it and you have an application that is single function to connect to your share. Now we are getting somewhere. Copy this file somewhere save, in my Macs I copy it to the root of “Macintosh HD” and then lets go to System Preferences.
Under the “Accounts” Preferences pane, select “Login Items” for the account you use to log in, and click the small + button to add an item to the list. I called my login application “ConnectHPVista64” and in the screenshot you can see it in my list:
I check the hide box so I don’t see it run and then I am done. Log off and log in and you should see your the dock icon bounce for a few seconds and then you should see the volume on your desktop (assuming you haven’t disabled them from showing.)
That’s it, hope this helps someone.
I am a software engineer, blogger, photographer, musician, technology enthusiast, father, husband, brother, son and obsessive compulsive weirdo. I enjoy riding bikes, watching movies, listening to music and reading like a mad man. If any of these topics interest you, you have come to the right place!












Reader Feedback