View Full Version : How to Auto Reconnect Network drive after sleep?

17th December 2007, 11:19 AM

I am hoping to get advise on how to automatically reconnect network mapped drives after resuming the mac from sleep.

I understand this is how OS X handles connections, and there are many threads on how to make connection easier. I personally have compiled the following script to connect and have added it to my dock and run it on startup.

tell application "Finder"
if not (exists disk "NAME") then mount volume "smb://STORAGE-B123/NAME/" as user name "user" with password "password"
end tell

I am wondering on how to either run this script on resume or re-instate the previously connected drive. BTW: running a timemachine every few seconds is not an answer for me.


17th December 2007, 02:10 PM
My suggestion is to get Leopard as the way it handles network shares is about 10x better.

Yes you can get the network shares to remount when ever you come out of sleep its just that it will never work every well.

18th December 2007, 08:00 AM
My suggestion is to get Leopard as the way it handles network shares is about 10x better.

Yes you can get the network shares to remount when ever you come out of sleep its just that it will never work every well.

Thanks TheOneWhoIsMany,

Does Leopard reconnect automatically on resume?
What do you mean "it will never work every well"? How do you do it, as I have found that from a resume the script does not start.

Thank You very much!

BTW: the main reason I ask, is that I store my itunes folder on a NAS drive which I connect to using SMB. Therefore, whenever I resume the Mac from sleep iTunes does not see its music library = it is not nice to reconnect every time manually.


18th December 2007, 09:20 AM
In Leopard, there is autofs, so it can be configured to automatically mount network shares (or anything really), at any intervals. Check this out: http://rajeev.name/blog/2007/11/22/autofs-goodness-in-apples-leopard-105-part-i/ and http://managingosx.wordpress.com/2007/12/11/autofs-in-leopard/

18th December 2007, 09:52 PM

Awsome. That is the key - automount seems to be the answer.
Unfortunately, that means an upgrade to Leopard, hmmm.
Looks like it is back to the same thing, more $ saves hassle.


31st July 2008, 01:27 PM
Thanks to BDAqua on discussions.apple.com for the most important first part of this.

Once you get the drives on the desktop, just get aliases to them, and then use those aliases to reconnect to the drives as a quick shortcut. And then you can use an Automator script to automate this, so a double-click on a desktop item opens all your needed drives instantly.

Here are the details.

1. Get the items on your desktop by connecting to the drives.
2. If you only have one (or few) you can drag it (them) to your dock, adjacent to the trash can.
3. Or, you can make an automation script that you can stick on your desktop or in the dock...
4. First, create a folder such as "Shares" in a convenient or an out of the way place. (You will only need to access it when you place new drives in it, and once in creation of the script.)
5. Drag the mounted drives into the "Shares" folder. OS X will make aliases there.
6. At this point, you can eject the mounted drives, and "opening" (say, by double-clicking) the drive aliases, and the drives will re-appear.
7. We can use this to make an Automator script.
8. Open Automator from its place in the Applications folder, or by getting it from Spotlight.
9. In the leftmost panel, "Library", select Finder to narrow the options.
10. In the Action panel, to the right, grab "Get Specified Finder Items" to the righmost panel.
11. Drag the folder you created earlier called "Shares", into the open area for "Get Specified Finder Items" in the rigtmost panel.
12. Drag "Get Folder Contents" from the Action panel into the open space below "Get Specified Finder Items" in the rightmost panel.
13. Drag "Open Finder Items" from the Action panel into the open area under "Get Folder Contents" in the rightmost panel.
14. You can test it by ejecting the drives (if they are open), and clicking the Run button in Automator.
15. If the drives show up on the desktop again, you're set.
16. First save it normally, as a Workflow, so you can edit it later if need be: In Automator, choose File->Save, and name it something like OpenShares Workflow.
17. Now save it as an application - choose: File->Save As..., and change File Format: from Workflow to Application. You can name it whatever you like. Mine's called OpenPCShares, and I saved this one to my desktop. You can even drag this to the dock (the left side) anywhere you like.
18. You can be done, but for a nice finishing touch, I liked changing the icon from the Automator Robot to the network icon. You can do this by connecting to a drive and doing Get Info on it, then click the *little* network icon at the top left, and select Edit->Copy. (If you can't copy, you didn't pick the right icon.) Then do a Get Info on the Automator script you created, and click the little Automator icon - again, top left, and then do Edit->Paste. Close everything up, and your done. Just try it out.
19. Oh, if you want to add drives later, just drag them into the Shares folder you created earlier. The script looks for the contents of the folders, so it should pick up anything new.

This was developed and tested in OS X 10.4.11.