7

I have a NAS and I connect to it as a network drive, however when I leave the house with the MacBook Pro and come back I have to manually remember to reconnect to the network drive. Is there anyway to do this automatically?

ControlPlane is not a solution as it currently has problems with macOS Sierra.

System version: macOS Sierra 10.12.5

7
  • 1
    Several solutions exist depending on your proceeding: do you shut down your Mac leaving your home, do you boot/log-in coming back home or is your Mac suspended/sleeping/power napping? Please add your system version! – klanomath Jun 14 '17 at 14:58
  • @klanomath I don't do any shutdown or logout. I close the lid, go to wherever I'm going, open the MacBook and do whatever work there close the lid, return home, and open the MacBook again. I have the login items set for when I logout or shutdown. However I rarely turn it off as I usually have it running background tasks I don't want to interrupt. – XAMPPRocky Jun 14 '17 at 16:19
  • 3
    Possible duplicate of App for changing between a work and private mode and similar q&a here. – klanomath Jun 14 '17 at 18:35
  • @klanomath I've updated the question with why ControlPlane is not suitable. – XAMPPRocky Jun 14 '17 at 22:35
  • @Aaronepower did you ever find a solution to this? – BlueC Apr 20 '18 at 7:07
2

I've been having the exact same problem and search for a solution. Eventually I found a few apps in the app store (I never normally look for software there!) that claim to be able to reconnect network drives after sleep:

Drive Mounty - I tried the pro version of this (£2.99) for a few weeks and it seemed to mostly work ok but suddenly started hammering the CPU and failing to mount the drive and also adding random suffixes to the mount point. The free version is restricted to 1 mount point and limited remounts. Was promising at first but sadly became unreliable.

Auto Mounter - Currently trying this (£9.99) with the Pro options pack too (£2.99). Looks good so far and has lots of features and the ability to create rules. Can mount drives in /Volumes using a separate helper utility that overcomes the App Store sandboxing. It's a shame there is no free trial version available.

Drive Mounter - Not tried this because Auto Mounter is holding up well so far. Has a free version too to try.

If you try any of these let me know how they work out.

1

I had the same problem as the OP. But I didn't want to have to add any apps.

So I use osascript to mount the file system. This solution does require you to save the credentials in the Keychain, but that only needs to be done once.

first I created the script file (credit to samuelfullerth for writing the script)

 nano ~/automount.sh

Then I put in this script (with changes to fit my environment)

if /sbin/ping -q -c 1 -W 1 <server ip goes here> >/dev/null; then
  if [ ! -d "/Volumes/<your volume>" ]  
   then
  /usr/bin/osascript -e "try" -e "mount volume \"smb://<your user name@server IP/your volume>\"" -e "end try"  
  fi
fi

After saving I changed the permissions

chmod 755 ~/automount.sh

Then I created a crontab entry to run the script every minute. I prefer nano for editing so I used this command. (there's probably a way to make nano the default)

env EDITOR=nano crontab -e 

Enter this into the crontab and save

* * * * * ~/automount.sh >/dev/null 2>&1

Now your Mac will stay connected to the NAS regardless. I got so tired of my Mac nagging me to reconnect to a drive that should always be connected.

Cheers

0

My solution for this is to use an Automator application, and a remounting script I wrote.

Part 1: Automating the Action

Using the Automator tool, I created a new Application, to which I added in order:

  1. Get Specified Servers action that gets my server (in my case, my raspberry pi)
  2. Connect to Servers, which connects to the server I've gotten in the prior action. It should look like the below screenshot.

automator app

Part 2: Checking to see if the computer is connected to the server

This automates the action of connecting to the server, but it doesn't automate the reconnection process. For that I wrote a simple script that I run on a cron job that checks (every 10 seconds) if the computer has connected to the server, and if the drive is mounted like I expect it to be.

The script checks:

  1. If my computer can ping the server
  2. If my computer has already mounted the drive in Volumes
  3. If my computer can ping the server, but the drive is not mounted, it runs the Automator application.
if /sbin/ping -q -c 1 -W 1 <server ip goes here> >/dev/null; then
  if [ ! -d "/Volumes/<your volume>" ]
    then
      open /usr/local/bin/remount/mount-drive.app
  fi
fi

Part 3: Checking every 10 seconds

The final part is in my crontab, to run this script every minute:

* * * * * sh /usr/local/bin/remount/remount.sh

That runs it every minute - if you want it to run every 10 seconds you've got to add in multiple cron jobs to run the script at 10 second intervals, a la:

* * * * * sleep 10; sh /usr/local/bin/remount/remount.sh

* * * * * sleep 20; sh /usr/local/bin/remount/remount.sh

* * * * * sleep 30; sh /usr/local/bin/remount/remount.sh

* * * * * sleep 40; sh /usr/local/bin/remount/remount.sh

* * * * * sleep 60; sh /usr/local/bin/remount/remount.sh

Honestly there is probably an easier way to do this with just Automator - I'm using three things (crontab, a script, and an Automator App) together that I'm sure I could probably just use the Automator App script if I was just better at it!

That said, it does the job - when I open up my Macbook, and the drive is disconnected, this makes sure that the computer reconnects within 10 seconds if it can connect to the drive.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .