Automatically connect to network drive on startup, wake up, and other ups.

Discussion in 'Mac OS X Server, Xserve, and Networking' started by Nigel123, Aug 31, 2013.

  1. Nigel123 macrumors newbie

    Oct 23, 2012

    So I just set up a network hard drive for my family so that we can access files from any computer, or watch movies from the TV without any need to plug and swap each connection.

    My issue is the initial connection to the HDD on start up, wake ups, and other reestablishments with the network.

    I've looked into the issue and found many many solutions that don't work. What my problem is the way my HDD establishes connection with the router. It's slow. Takes about 1-2 minutes, while the computers take less that 30 seconds.

    What is occurring is the computer starts up and goes, "Oh network isn't available," and then doesn't try to connect.

    I found this guide: but I don't really understand it. I've used terminal before, but after I enter the first line I don't see what should come next.

    So what I'm really asking: Is there a way in OSX ML to automatically connect to a network HDD when it sees it is ready, rather than try and connect when it is clearly not available.

    Additionally, please avoid "Leave the HDD and router on all the time" because that is not how we roll and if it were this question wouldn't be posed.
  2. Weaselboy Moderator


    Staff Member

    Jan 23, 2005
    We should be able to fix you up with an Applescript to mount the drive then put a delay XX command at the beginning of the script to delay it running.

    What is the path to the network drive and I'll try and help you with the Applescript.
  3. Nigel123 thread starter macrumors newbie

    Oct 23, 2012
    Sorry I took so long!

    I wasnt notified and got busy to check here!

    It's located at: /Network/NAS/Media

    My concern is that is this script going to run only at login or will it always detect if the drive is online?

    I would like it to be.. okay imagine you have a macbook, router, and nas hard drive. The power goes out, the macbook is fine because of battery, the router and has go out. Then the power comes on, you automatically reconnect to the router because your macbook is constantly checking for that connectivity. The hard drive however, is offline. My preference would be for it to say, "Oh I see the hard drive connected to the router I'll automatically connect" to "Oh it's offline I'll try and connect to see if it was interrupted" to "Oh it's definitely offline, no response" to hours later when it is online, "Oh I see it connected now, I'll list it in the connected severs".
  4. Weaselboy Moderator


    Staff Member

    Jan 23, 2005
    Paste this into the Applescript Editor app and save it as an application, then add it to your login items. This will launch the script at login and delay 30 seconds before mounting the NAS drive. You can test it in Applescript Editor first to see if you need to extend the 30 seconds.

    Also, manually mount the drive and select it in Finder then do a command-i and look at the path to make sure it matches the section in quotes.

    This should get you the delay you want at startup.

    As far as making sure the drive stays mounted, that is a bit more complex. OS X has a utility called autofs that can be used to monitor networked drive and remount them. I am only slightly familiar with it... so you will need to research how to cobble together that piece yourself.

    delay 30
    tell application "Finder"
    		mount volume "smb://Network/NAS/Media"
    	end try
    end tell
  5. AndrewSBreck macrumors newbie

    Dec 7, 2013

    Anyone built something like this?
    I have a network server at home, and all I want is for it to automatically connect if it is available.

    so basically:
    if ({Volume} isAvailable && !Connected)
    connect to {Volume}
  6. dimme macrumors 65816

    Feb 14, 2007
    SF, CA
    When I startup my mac I also want to connect to my network drive. I just added it to the login items and it is always there. Now if you are having a problem because you share is not available right away, perhaps we should work on that problem. I use a mini server with a attached drive and the volumes are always available. So is you nas always available to the network?
  7. moez macrumors regular

    Jun 6, 2007
    Did you figure out how to do it?
  8. CJM macrumors 65816


    May 7, 2005
    Thread necro, yay! After some Googling I found this thread. Would love to be able to do what was mentioned here:

    if ({Volume} isAvailable && !Connected)
    connect to {Volume}

    I have my Time Machine disk image on a network drive, which requires manual mounting every time I'm in the office. Obviously, I forget quite often, leading to weeks between backups. Is this doable via Applescript? I have an alias of the disk image on my desktop, so it's simply a matter of mounting it when the network share is available.

    I last touched Applescript on Mac OS 10.1, to write some silly prank back in my teens. I have no idea what I'm doing.
  9. dwfaust macrumors 601


    Jul 3, 2011
    It’s not an automated solution, but it is pretty simple to remount the drive using Finder.

    I have a public share on my Drobo-FS named "Public". To set it up to reconnect, do the following:

    Open Finder.
    Press CMD-K.
    Enter the smb path in the dialog box (smb://Drobo-FS/Public).
    Click the + button to add it to the list of devices.
    Click the [Connect] button.

    Now, when the drive gets unmounted, re-mounting is a simple as opening Finder and pressing CMD-K [enter]

    Attached Files:

  10. mvmanolov macrumors 6502a

    Aug 27, 2013
    You could automator to make a app that will automatically connect at login...
    Pause (3sec)
    get specified server
    connect to server
    done :D
  11. CJM macrumors 65816


    May 7, 2005
    As a login app only, or can it be executed when entering password after waking from sleep? I don't really turn off my laptop.
  12. mvmanolov macrumors 6502a

    Aug 27, 2013
    well, automator is quite powerful, so you may be able to do that. for example you can make the same app as a "service" and then create a "workflow" that will do that.... i may try this myself actually. LOL (though in the interest of full disclosure, i'm by no means an automator expert...)
  13. AntonioMello macrumors newbie

    Nov 10, 2014
    This is how I made it work here

    Hi guys, this is what I have in AppleScript that was able to mount my network HD connected to an Airport Extreme. I didn't want to install a 3rd party app just to do this, so I researched a bit online and ended up with this working solution, hope it helps.

    Open Apple Script Editor and insert the following (changing what's indicated in red), save it so you can edit it easily, then export it as an application.
    Remove the lines in red when you copy to applescript, as they're just instructive:

    This first line below creates a delay to start the script (in seconds), it allows your computer to connect to the wifi before the script is run. If you think you need to make it longer, just change 5 to the value you'd like.
    delay 5

    -- Check IP address is reachable

    set IP_address to ""
    change the IP address above for your IP of your router (airport extreme in my case). Remember to setup your airport extreme to use this IP address as static, so it doesn't eventually change.

    set IP_Valid to true

    do shell script ("ping -c 2 " & IP_address)
    on error
    set IP_Valid to false
    end try


    set SSID to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk '/ SSID: / {print $2}'"


    if SSID is "Greta" or IP_Valid then
    Change Greta for the name of your wifi network as it appears on your wifi monitor


    mount volume "afp://YourUser:YourPassword@"
    On the above line, insert the user and password you use to connect to the network drive. Change the IP "192...17" for the IP of the router, same as you did some lines above. Change "My%20Shared%20Folder" for the folder you'd like to connect to on the remote disk. Notice that if you have spaces on the username, or folder name, change the spaces for "%20". If you don't need a user and password to access your HD, just remove the part "YourUser:YourPassword@" from the code above


    set endresult to "got it"

    -- ELSE




    set endresult to "fail"

    -- END

    end if

    That's it. Now that you've exported it as an application, test it and you should see your drive mounted.

    Now let's make this application run when your computer logs in. Go to System Preferences, Users & Groups, select your user, click the lock at the bottom left to allow changes, choose "login items", click the + button, find your application and your good to go. Just log out and in again, your driver should mount automatically after the specified delay time.

    Still figuring out how to amend it so it runs on system wake, if anyone has an idea, it'd be great to know.

  14. marxspawn macrumors newbie


    Mar 31, 2017
    I am using a 4TB external hard drive connected to a wireless router via USB for Time Machine
    This code did not work until I mounted the volume first, then attached the sparsebundle
    Hope this helps
    tell application "Script Editor"
            tell current application
                                       -- First mount NAS Folder
                mount volume "smb://192.168.xx.xx/yourVolume/"
                                       -- Allow time to mount
                delay 20
                                       -- Now run script to attach Volume as a Drive
                do shell script ("hdiutil attach -mountpoint /Volumes/TimeMachine/ /Volumes/yourVolume/TimeMachine.sparsebundle")
            end tell
        end try
    end tell
  15. blakey42 macrumors newbie


    Oct 28, 2017
    Hey had this same issue and found an in the App Store called AutoMounter. Works great!

Share This Page