jeffcoughlin.com

Mac Bootup - Mapping/Mounting to Windows Shares Automatically

I'm currently using Mac OS x 10.5 and originally had these scripts while using 10.4 (thus I haven't tested them on any earlier versions).

Normally when you want to map (mount) to a Windows shared network drive you have to click on the word "Go" in the finder menu, choose "Connect to Server..." (propeller-K), and use SMB to mount to a Windows shared server.

Example:

view plain print about
1smb://workgroup;userName@192.168.1.10/shareName

However, I have several shares I use on my network (a NAS that uses SMB) and I prefer to have my shares connect automatically on startup. So I use the following script to map to my drives (using Apple's Script Editor).

view plain print about
1try
2    set ping_result to (do shell script "ping -c 1 -t 2 -i 2 192.168.1.10")
3    mount volume "smb://workgroup;userName@192.168.1.10/shareName"
4end try

From there I can either add all the drive mappings I want to that one script, or save them as individual scripts (the way I usually do it). Then I save the script as an application (make sure to uncheck "Startup Screen", unless you want that extra step).

Finally I add the applications to my startup (System Preferences --> Accounts --> Highlight the account --> Login Items (tab) --> Then I add the applications to the list.

On some occasions (for some reason), when my machine starts up not all of the mappings will connect (giving an error that the destination was unreachable). I haven't figured out why yet, but it only happens occasionally, so I've been living with it (to fix it I just manually click the application again and I'm in).

There are plenty of other methods to get this to work, but I haven't had much luck with others yet (I'm still a bit new to Mac and *nix). If someone else out there has a great idea (or a better one), feel free to let me know.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Troy Allen's Gravatar That looks like a good script, but I use a much more "low tech" solution: I simply mount the drives, and then create aliases (shortcuts in Windows speak) to them in the right side of the Dock (near the Trash). I am on a laptop, so quite often I am not on the same network as my shares. So if I use a script at login, it tries to mount drives that are not available. By using the aliases, I can simply click on them in the dock when I know I am on the appropriate network, and the drive mounts automatically.

You can also simply add the mounted drives themselves to your Login items, but that causes a new finder window to be opened for each drive (and it has no "error checking", which is what I assume the "try/ping" portion of your AppleScript handles).
#1 by Troy Allen | 1/29/08 1:59 PM
Jeff Coughlin's Gravatar Thanks for the tips, Troy.

> I am on a laptop ... So if I use a script at login, it tries to mount drives that are not available.

I am on a laptop as well (although I am at my home office more than anyplace else). That's why I'm using a try/catch (well, try anyway). First the script tries to ping the location (with a 2 second response timeout). If the ping fails within the 2 seconds, no harm done (and no hangs or lockups for the user). I could then do the same thing you're doing where I create aliases to the applications (compiled from the scripts) for times where manual connection is required.

I'm hoping that one day OS X will have a more user friendly auto-mounting feature in the future to connect to things like Windows. But for now, this workaround seems to work well for me (until I find a better solution)
#2 by Jeff Coughlin | 1/29/08 2:34 PM
Troy Allen's Gravatar Makes sense...I may just give your script a try as well. Just to be clear, I am currently creating Aliases to the mounted drives themselves -- not any kind of mounting script. So it is much easier for the "average Mac user" to implement, in case you need a solution for someone less technical than you and I.
#3 by Troy Allen | 1/29/08 2:42 PM
Peter's Gravatar Great info!
#4 by Peter | 6/29/08 9:38 PM



BlogCFC 5.9.8.007 by Raymond Camden | RSS | Contact Blog Owner