macOS users - AutoMount your Shares

Recommended Posts

**** UPDATE ****


macOS 10.12 Sierra breaks this script. I've developed an application to get around this issue. Available here:




AutoMounter is a sleek and powerful menu item designed to automatically mount your network shares.


- Supports SMB / AFP / NFS network shares

- Supports multiple NAS appliances / servers

- Server discovery

- Persistent auto mounting of shares, when the server is reachable

- Match a server to a WiFi Name (SSID)

- Reacts to changes of network

- Optionally send a Wake On LAN packet to a server when the network changes

- Easy to use, unobtrusive, menu bar item

- Optionally hide shares from Desktop

- Resolves macOS Sierra authentication issue



Thought I'd share my quick and simple bash script (with the help from Stokkes) for mounting AFP/SMB shares. Set your preferences, add the shares, and it will ping the server. If it is available then it will mount the shares. There is also an option to load iTunes at the same time.


Now works with Lion.


**NEW** Added functionality to wake the server via WOL **NEW**

28/12/2012 - Added the ability to call "wake" at the end of the script to wake the server, no matter which time it is. eg: /scripts/ wake


You must have wolcmd (included) in the same folder as the script. This is a definable directory. If the server is unavailable via ping, WAKE is set to TRUE, and the time is within the hours specified, then the script will attempt wake on lan. You must have your server MAC address and subnet in the options. This is all shown in the script.


Now if the server is unavailable it will exit iTunes. I found iTunes to be unstable if it can't resolve links to its music. You can set this in the script


Step 1: Where to put &


- Create a folder called "Scripts" on the root of your hard drive. This could be /Macintosh HD/Scripts.

- Copy to this folder.

- Copy to your user *Username*/Library/LaunchAgents folder. If the folder doesn't exist, create it.


Step 2: Editing the mount script


- Open in text edit. Read the notes at the top of the script.

- Enter your username and password inside the quotation marks where shown. Read the notes in the file if your password has symbols (eg @, as you'll need to url encode them). Site is given in the script.

- Enter your server IP address (eg "") and hostname (eg "tower") where shown. If your nas has a dynamic IP address (DHCP), enter the hostname instead of the IP Address.

- Leave Mount point alone, unless you want the shares to mount somewhere other than the default /Volumes

- Enter TRUE or FALSE if you want iTunes to open or not.

- Enter the protocol you want to use, either smb or afp.

- Enter the shares you want to mount. The shares must be space seperated (eg "TV Movies HD%20Movies". If the share name has a space in it, replace the space with %20 (eg "TV%20Shows").


Step 3: Enable script


- Double check the settings are correct, and make sure the, and files are in the correct place.

- Open Terminal (Applications/Utilities/Terminal). The sudo command will need your administrator password. Type:

                  - sudo chown root:staff /Scripts/

                  - sudo chmod 775 /Scripts/

- Restart your computer. It should mount your shares on login, and check if they're mounted every one minute.


If it's not working, double check permissions and settings. Try running the shell script by opening Terminal and typing:


- /Scripts/

- Press enter


If that works, then check the status of the launchd agent by going into Terminal and typing


- launchctl list

- This will display the loaded launch daemons. If there is a 1 next to the file, make sure the script is located on your boot volume, "/Scripts/". If it's not in the list at all, make sure that the plist in your user Library folder, in a folder called "LaunchAgents".


Hope this is useful for someone!

Link to comment
  • Replies 232
  • Created
  • Last Reply

Top Posters In This Topic

Cheers! I've found a solution for quitting applications by their real names via terminal (not process ID, which tends to change often), and it will prompt to save documents first, or exit quietly. Unfortunately doesn't work with iTunes, as iTunesHelper daemon conflicts with the name.


If you need this, let me know.


You can also decide to umount Volumes if there server isn't available, where the else statement is. In the else statement (at the bottom) remove exit 0 and add umount /Volumes/Music etc.

Link to comment

I'll take a look at it when I get home this evening.


I've been meaning to make a script that'll run on a set schedule (read: often) to make sure my volumes are still mapped. I often have an issue in Plex where the volumes get unmounted (either the Mini goes to sleep or something else happens) and I can no longer stream my media. I'm then forced to vnc into the mini and remap the drives manually.. PITA.


So if this does what I've ben meaning to do, then fantastic.

Link to comment

Exactly the reason why I made this script  ;)  Also doesn't try and open the Volume in a window, like if you add the mounts to your login items. They just mount quietly in the background, and only if they're not mounted already and the server is on.


Very useful if you run plex, or if you have iTunes running all the time, and your library is sitting on the shares.


It runs every minute, so you're seldom left without your volumes mounted.


Also, remember to put in the LaunchAgents folder in your user folder. If you use the main Library folder, it won't work.

Link to comment



I've actually written a quasi Microsoft DFS mounting script (seeing as it OSX doesn't have built-in DFS support) and learnt a lot about mounting shares from the command line.


The password is truly a bugger, especially with symbols, etc. For example, the character "!" is a valid URL character and doesn't change during the url encode process, but wont' be accepted on the command line (have to change to %21). Very weird and frustrating :)



Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.