Philoking.com

24 Sep, 2008

How-To: Auto-Connect to Windows Shares from OS X

Posted by: Jason Burns In: Mac| Windows

Picture 1 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.

Picture 2

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:

Picture 3

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.

3 Responses to "How-To: Auto-Connect to Windows Shares from OS X"

1 | Arnan

September 25th, 2008 at 1:35 am

Avatar

That’s nice and all but while this script runs applescript blocks all finder actions and input.

Thus if your login procedure is slow, say it takes 30 seconds before the remote locations authorizes the mount, finder cannot do a thing and seems hung or stalled.

This can be very annoying.

In this case, like automounting shares i would much rather run a shell script a-la terminal as a startup item since you don’t actively use terminal in normal use.

The ending result is the same.

2 | Jason Burns

September 25th, 2008 at 12:28 pm

Avatar

Thanks for the tip Arnan, why don’t you leave a more detailed comment telling our friends how to do that?

3 | Arnan

October 1st, 2008 at 4:23 am

Avatar

mount -t afp afp://user:pass@hostname/volume_to_be_mounted /Volumes/mount_point

I would use:
mount - afp afp://arnan:mypassword@storage.local/Arnan /Volumes/arnan

Should do the trick, where mount_point would be the name shown on the desktop.

Comment Form


About

jbpic 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!

Flickr


Feeds

  • View in iTunes
  • Any Podcatcher
  • Any Feed Reader