Quick Tip: How to mount a TimeMachine network drive at login

Quick TipI’ve had a lot of feedback from my article on using readyshare drives for TimeMachine backups. The one glitch I’ve found is that I have to remount the sparsebundle file every time I log in. Here’s a way to fix that issue. 

You may have seen articles that have you simply drag the drive  into your Login Items profile to have it remount on login. This hasn’t worked for me. It may be due to the fact that the readyshare drive has to be mounted first, I’m not 100% sure. However, we can create a simple AppleScript that will do the job for us.

Fire up the AppleScript editor (under Applications) and paste in the following script:

mount volume "smb://readyshare/MacBackup"
end try
do shell script "hdiutil attach -mountpoint /Volumes/MacBackup/ /Volumes/MacBackup/TimeMachine.sparsebundle"

Note: Your path(s) will vary based on your share and sparse bundle names.

Before running this script, make sure your readyshare drives have been unmounted. Click the “run” button and verify the results. If you open up Finder, you should see your ReadyShare drive in the “Shares” section and your Time Machine drive listed in the “Devices” section.

If all is successful, use the File->Export dialog, making sure to change the format to “Application”. You can name it whatever you’d like.

Once this is done, open up the “Users and Groups” settings, select your profile, and drag the application file from finder into the Login Items section.

Next time you reboot your computer, all your drives should come back for you automatically.



31 thoughts on “Quick Tip: How to mount a TimeMachine network drive at login

  1. If I may, I’d like to offer a suggestion to the script above. The whole thing failed when I wasn’t in the same network as usual, so just to save me a couple of clicks, I added

    on error

    Just above the End Try line. If the share is not available, the script stops quietly there.

    Thanks for this. It really helped and saved me hours of frustration.

    1. Good catch. I personally like to see an error message like this so I can diagnose things further, but since you have first comment, others will be able to see this and update their scripts as needed. Thanks!

  2. The first command works without a hitch. The second command returns this error: error “hdiutil: attach failed – Permission denied” number 1. Any advice?

    1. Either try putting sudo in front of the command to run as root or make sure in the ReadyShare settings that you don’t have your USB drive access password protected.

  3. And on that point are 87 results; an hour ago from Matt is– on
    that point’s dozens of riots. So why would you and tied if it does
    deficiency, buy twitter followers using paypal I believe our braveness to try new things is what disunites us from early masses.
    As you can see to me.

  4. This all works but my drive unmounts when my Mac goes to sleep. Do you know of a way to run the script on wakeup event?

    1. I’m working on a permanent solution for this myself. I created a script file to auto mount the drive (see the link in this article), but haven’t found a good tool or script yet to detect when the connection is lost

      1. Thank you so much for your tutorials!
        You can use ControlPlane (found at http://www.controlplaneapp.com) to run your script on a wakeup event.
        Here’s what I did:
        – Create a Context. I named it TimeMachineAtWake
        – In the Evidenced Sources tab, make sure Sleep/Wake event is selected
        – Go to the Rules tab. Set a Rule to “Sleep/Wake” at 100%.
        – Go to the Actions tab. Click the plus sign menu, select Application Actions, Select Open File or Application, select your Applescript app. Make sure to select from the Context menu and that it’s set for On Arrival.

        With this in place, you don’t have to have your script in your Login items anymore. The only issue I’m having so far is that I get an “hdiutil:attach failed- No such file or directory” if the network drive hasn’t unmounted yet. I’m guessing there’s something in ControlPlane that I can do, I just haven’t figured it out yet.

        1. I was able to fix my issue with the hdiutil:attach error when the network drive was still mounted. To get my drive to unmount, I made another Applescript app, with shell “hdiutil unmount /Volumes/volumename” and told ControlPlane to open that when the computer goes to sleep.

          I’m not even qualified enough to be called an amateur with this stuff, as I use Google to learn how to do pretty much anything, so there may be a better way to do this. :)

  5. I do not recognize any script in this post. Is this right? And could somebody please send me the script?

  6. The issue I’m having is that when I restart my Mac, the script runs before the network adaptor gets the chance to connect to my WiFi network! Has this not happened to other people?

    1. Correct. If you have a password protected drive, I’m not sure how to help, unless you can setup a script that will mount it with the username and password. This solution assumes you leave that share open on the network.

  7. I found that TimeMachineScheduler beta (works with MacOS Sierra) can be used to auto mount your TimeMachine sparsebundle which is in turn mounted by SMB (do away with AFP altogether for something stable). This is checked each time before scheduling a backup, so your backup disk can spin down between backups.


    1. Below is the Applescript to run to specify a custom condition to skip the backup. This can be set within the Advanced tab of the program. It is supposed to be able to automount things, but this script will mount the spxrcebundle if it is not mounted.

      Note: I have the /Volume/Backups already mounted as an SMB mount from a network drive, and is automounted at login using System Prefs -> Users&Groups -> User:Login Items -> (Drag or add Volume to List)

      Sorry this is brief. I have been searching and trying to put this together, rebooting, testing, for a few days now. I have been using asusWRT Merlin on a Netgear R7000. I hope it helps someone else trying to get network Time Machine backups working using SMB and sparcefiles on MacOD Sierra.

      MacLappy:~ Stuart$ cat /Users/Stuart/mount-timemachine.scpt

      set diskName to "TimeMachine"

      tell application "System Events" to set diskNames to name of every disk
      if diskName is in diskNames then
      log "found"
      return false
      log "trymount"
      do shell script "hdiutil attach -mountpoint /Volumes/TimeMachine/ /Volumes/Backups/MacLappy/TimeMachine.sparsebundle"
      on error
      log "failed to mount"
      return true
      end try
      end if
      return false

      1. This above script includes log lines, but the TimeMachineScheduler will error if any script attempts to send output to the screen, and you can see this in the programs log file.
        So you can test the script yourself with:
        osascript ~/mount-timemachine.scpt

        Finally, comment out the log lines with a # to use the script in the program.

        Cheers, Stuart

What are your 10 bits on the matter? I want to know!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.