Blog Post

Auto-Remount Disconnected Shares

Some server administrators set share drives to auto disconnect users after a set time of inactivity (ie fifteen minutes). As a user it’s super frustrating to connect to a server every time you need access. I’ve written an AppleScript that first checks to see if the share is mounted, if it is mounted it does nothing; however if the share is not mounted the script will auto-mount it.

Let’s first start out by downloading the script from here:

Timeout Apple Script (ZIP)

After your download is complete unzip and open the script the script (double click it to launch the OS X script editor). To being using this script you will have to know: the IP Address of the server you are connecting to, the name of the folder you want to connect to, your username, your password, and the amount of time in seconds that you want between connection attempts (idle time). All of the items in purple in the picture below are the ones you are going to need to edit (Make sure to remove all the parenthesis – completely replace everything in purple).

Once you have input all your information, go ahead and click the “Run” button to test it. If everything is working properly the share should mount. After you confirm your script is working, it is time to save it as an application:

  1. Go to File > Save As
  2. File Format: application

  3. Check the following Options: Run only, Stay open

  4. Click save

Ok, now we have an application so go ahead and drop it into your applications folder on your Mac. I have a folder under Applications called “scripts,” to help stay a little more organized. To take this to the next level, I went ahead and put it in my Login Items so that it launches when I start my Mac, and I’m immediately connected to the shares.

To add the application to the Login Items:

  1. Go to Applications > System Preferences
  2. Go to Accounts

  3. Go to the Login Items tab

  4. Finally, drag and drop your application into the Login Items list.
  5. Congratulations! Your computer will now auto-mount your share when you start her up, and keep you connected throughout the day.

As a side note, this script is far from perfect. When it’s running it freezes finder for a few seconds, and it must be force quit when restarting, but it’s a great solution if you do not have administrative access to the share. Have fun!

6 Responses to “Auto-Remount Disconnected Shares”

  1. Olivier C

    I personaly use more or less the following command line as cron job:
    osascript -e “mount volume “smb://user:[email protected]/name””

    With the Login Items, I think the drive will never get connected if the server is down at the time of login, which is definitely an issue for me (my NAS is not always on).