macOS Sierra Automount on Startup

I have a little Script as Startup-Object:

https://picload.org/image/rrrpioli/bildschirmfoto2016-07-06um17.3.png


In this Script 2 Shares from my NAS (nas.box) and a Raspberry Pi (Raspi3) should mounted on Startup. This worked with El Capitan without problems. Since macOS Sierra Beta 1 the Script loads and mounting starts after startup but asks for my Login-Data. Username an Passwords are filled, but i must click on "Connect". For the NAS-Share, the Option to store the Login-Data to Keychain is checked. On the Raspberry-Share it's not checked, but the User-Data are also filled.


https://picload.org/image/rrrpioli/bildschirmfoto2016-07-06um17.3.png


https://picload.org/image/rrrpiolw/bildschirmfoto2016-07-06um17.3.png


The Problem is, that this occours every time, when i reboot my Mac or Logout/Login to my User-Account. I've tried to delete the Objects from Keychain, but it doesent change anything.


Any suggestions?

Accepted Reply

Here is how I am dealing with it.


Go to your home folder ~ and create a folder named Server. Open the newly created Server folder and make another folder named Drive.


Then launch Applescript Editor and create a new script like so:


do shell script "mount_afp afp://user:password@ip_address/Drive ~/Server/Drive"


You will need to enter your particulars here. Example : "mount_afp afp://bob:xyz123@192.168.1.100/bob ~/Server/Drive"


Save your script as an application.


Open System Preferences - User & Groups - Login Items. Drag your script application into the box for automatic login items. Reboot.


Your drive should be on your desktop.


Good luck.

Replies

You create the folder in your home folder of your Mac's hard drive. Double click on your Mac's hard drive. Then double click on users. Click on the icon of a house (your user name should be under the house). Navigate to the menu bar. Choose File. Then New Folder. Name the new folder Server. Double click the new folder named Server. Then navigate to the menu bar. Choose File. Then New Folder. Name the new folder Drive. Close out all of the windows.

Okay, I think I have a solution to this that will work for me at least.

I wasn't interested in mounting the network shares to a user folder instead of inside the default /Volumes folder.

I tried adding a symbolic link to the /Volumes folder to a new location where the network shares would be mounted but that symbolic link is deleted on reboot.

But then I thought after reading some of the advice here: What if I have a volume on the local drive called "Network_Shares" or "Network_Storage" that I mount all the shares inside? This "Network_Storage" volume would then live inside the /Volumes folder and the shares would live inside it....keeps it nice and clean and easy to access.

Here's what I did to work around this issue:

Opened up disk utility and added a small partition (100MB) but it can be much smaller.

This partition will only serve as the root level for mounting network volumes is is automatically mounted every time the mac boots up.

Then I altered my applescript I originally posted near the top of this thread to read as follows:

--

--

--

--

--

--this first part is for my macbook only so it doesn't attempt to mount the shares unless I'm at the location where the wifi SSID is broadcast

set theWifi to "MySSID" -- the wifi SSID

set theList to paragraphs of (do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s| awk '{print $1}'") -- get the wifi list

if theList contains theWifi then

set serverAddress1 to "UserName:Password@Server-Address/Share_Name1"

set serverVolume1 to "Share_Name1"

set mountPoint1 to "/Volumes/Network_Storage/Share_Name1"

-- the line above might also be changed to set mountPoint1 to "Volumes/Network_Storage/" & serverVolume1

tell application "Finder"

try

if disk serverVolume1 exists then -- do attempt anything since it's presumable already mounted

else

with timeout of 3 seconds

do shell script "[ ! -d " & mountPoint1 & " ] && mkdir -p " & mountPoint1 & " || echo directoryOK" -- create the folder to host the mount point if it doesn't already exist

do shell script "mount -t smbfs //" & serverAddress1 & " " & mountPoint1

end timeout

end if

end try

end tell

set serverAddress2 to "UserName:Password@Server-Address/Share_Name2"

set serverVolume2 to "Share_Name2"

set mountPoint2 to "/Volumes/Network_Storage/Share_Name2"

tell application "Finder"

try

if disk serverVolume2 exists then -- do attempt anything since it's presumable already mounted

else

with timeout of 3 seconds

do shell script "[ ! -d " & mountPoint2 & " ] && mkdir -p " & mountPoint2 & " || echo directoryOK"

do shell script "mount -t smbfs //" & serverAddress2 & " " & mountPoint2

end timeout

end if

end try

end tell

end if

display alert "**** on this Apple!"

delay 10 -- check for drops every 10 seconds, may not need this anymore as it was added back in Mavericks, it's an enless loop so if you unmount a volume it will mount back within 10 seconds

end repeat

@Atarimac


Thank you for the hint🙂

This works for me -> mount -t afp afp://user:pass@192.168.1.100/Data ~/Server/Drive

Hi,


I tyied 2 mthods


1. Mount the net disk under /Users/user/mountpoint

2. Create a new partition and mount net disk under /Volumes/newpartion/mountpoint


Both methods could mount the net disk properly, but I still face some access issues.


When I was trying to copy a movie from mounted net disk, it shows "I cannot copy the file, you do not have the read access"


Anyone got the same problem?


Thanks


===============================

Sorry about that, got the problem, something wrong with my net disk NTFS Security Settings~


I reset the disk security access, took the ownership access with current user.

Try this for auto mounting your SMB / AFP / NFS volumes: https://itunes.apple.com/us/app/automounter/id1160435653?ls=1&mt=12


I ran into the same problem, so I developed around it.

The problem is fixed for me. Automount works again.

Here is what I did:

- deleted the old shared volume item in user startup items.

- deleted any entrys regarding the NAS (Synology) in the keychain.


PLUS:


- installed the latest cricial update for my Synology NAS (6.0.2 update 2)


Then:

restart Mac, connect to shared volume in finder with cmd+k, drag connected share into user startup items.

-> automount works again.

HI @atarimac


Thanks for your reply but I can't get it to work.


I've created the folders where you told but I don't understand how it can "find" the NAS shares.

Plus the script returns me a number 2 error.

What credentials and what IP should I write ? The NAS's ones ? or the Mac's one ?



In fact none of the above soutions works for me..



I'm desperate...


Anyway thanks all for all the solutions.

Andrew,


I bought your Automounter app, but must admit I am a bit dissapointed... I can't use the NAS name as defined in the settings on the NAS???


My NAS is named "BMK-rnp", and that name works in Apple scripts, and in Finder the NAS shows up as "BMK-rnp (AFP)". However, I can't use it in your Automounter app, and only if I use the IP address does it work. I do not want to use the IP address, because then I have to rescan all my apps that have links to files on the NAS. Hence it is not feasible for me.

I also have a similar problem. In El Capitan, the following applecript mounted my Synology disktation NAS volumes. Now in Sierra, it fails to find my diskstation drives (does not exist or is not available) and then gives an error -5016.


tell application "Finder"

mount volume "smb://DiskStation/Volume1/Video" as user name "Ralph Quinones"

mount volume "smb://Diskstation/Volume1/Music" as user name "Ralph Quinones"

mount volume "smb://Diskstation/Volume1/Photos" as user name "Ralph Quinones"

mount volume "smb://Diskstation/Volume1/Downloads" as user name "Ralph Quinones"

mount volume "smb://Diskstation/Volume1/Documents" as user name "Ralph Quinones"

end tell

I am not a programmer and was able to build this a few years ago by googling it. Now I am trying to find help on how to rewrite the script so it works and mount my NAS drives whenever my MAC boots. If I try to do this in user/login in preferences, only 2 drives mount. Never been able to make all 5 mount from user login preferences.


Any ideas how to rewrite the mount volume so it works? I remarked my original mount volume statements, and used the following line:


mount volume "afp://192.168.1.41"


This does not crash the apple script. It prompts me to enter my password, then I can select the drives I want to mount, and it it works. Does anyone know how to automate loading all 5 drives without having to authenticate and select the volumes?


Thanks in advance for your help.

mount volume "smb://DiskStation/Volume1/Video" as user name "Ralph Quinones"


code above will mount volume into /Volumes folder by default, since macOS Sierre has changed the /Volumes folder privilege, so one of the solution is to mount the volume to a mount point within home folder;


mkdir -p ~/DiskStation/Video
mount -t smbfs smb://YourUserName:YourPassword@DiskStation/Volume1/Video ~/DiskStation/Video


Hope it helps~

Finally I got it working with your solution!


After re-reading the whole thread 2 times, I now understand how it's supposed to work!


So I'll answer myself and explain it for people like me :


I did create those two folders like you said 3server" and "Drive" and I wrote exactly this script :


do shell script "mount_afp afp://NASusername:NASpassword@NASIPadress/NAMEoftheVolumeinNAS ~/Server/Drive"


As i Have several volumes in my NAS, I struggleded a little more when I had the idea to launch my originial mounting script and it now works perfectly !!


So to be clear, i launch the first script as a Sierra credential and the second as it was already to mount all my drives (10 in my case).


A huge thanks to everyone over here !!


alban

@andrewha I created a developer forum account just to say thank you! I bookmarked the Automount post you presumably did on Lime Tech & I've been using the scripts & instructions for a few years now on various macs. Discovered this post when looking into having to fix the issue (I check the Lime Tech post a few days ago but it's old so didn't expect an update). Downloaded your app, it works great... Then went back to the Lime Tech (to find the lcoations to remove the launch files) & saw your update! So, thanks for the scripts & especially the new app!


To all others, I'd advise getting this app, it's definitely the best way of creating these mounts...

Thanks man! I used your script and altered it a little. Now I finally have a working automount on my NAS shares!


I changed your script, because of a few reasons:

1. It goes on eternally and on shutdown of my Mac, it prevents the shutdown (I created an app out of the script). I only want to run it on boot, so no eternal run necessary. So I added a maximum number of tries (in my case set to 5)

2. It doesn't mount when I plug in my ethernet cable with a shutdown wifi. I want it to mount also over the ethernet, so I added this check

3. I cleaned it up a little, using a little more variables and a function call


Here's my script:


set NrMounted to 0

set MaxMount to 4 -- max number of networkshares to mount

set NrTries to 0

set MaxTries to 5 -- max tries before quit

repeat while NrMounted is not MaxMount and NrTries is not MaxTries

set theWifi to "********** Fill in your Wifi SSID here *******************" -- the wifi SSID

set theList to paragraphs of (do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s| awk '{print $1}'") -- get the wifi list

set EthernetStatus to do shell script "ifconfig en0 | grep 'status' | cut -d ':' -f 2 | tr -d ' '" -- get ethernet status

if theList contains theWifi or EthernetStatus = "active" then


if MountedSuccessfull("****** fill in the name of your first share here *************") then set NrMounted to NrMounted + 1

if MountedSuccessfull("****** fill in the name of your second share here *************") then set NrMounted to NrMounted + 1

if MountedSuccessfull("****** fill in the name of your third share here *************") then set NrMounted to NrMounted + 1

if MountedSuccessfull("****** fill in the name of your fourth share here *************") then set NrMounted to NrMounted + 1


end if

set NrTries to NrTries + 1

delay 10 -- waiting time before next try

end repeat

on MountedSuccessfull(VolumeName)

set NASUserCredentials to "****************** fill in your usercredentials on your NAS shares here. In the form: user:password ******************"

set NASIP to "***************** fill in the IP of your NAS here. for example: 19.168.1.112"

set MountPointFolder to "******************** fill in the place where to mount on your Mac here. for example: /Users/yourname/NAS/ (don't forget the last '/') ****** "


set Mounted to false

set serverAddress to NASUserCredentials & "@" & NASIP & "/" & VolumeName

set mountPoint to MountPointFolder & VolumeName

tell application "Finder"

try

if disk VolumeName exists then -- it's presumable already mounted

else

with timeout of 3 seconds -- try to mount

do shell script "[ ! -d " & mountPoint & " ] && mkdir -p " & mountPoint & " || echo directoryOK" -- create the folder to host the mount point if it doesn't already exist

do shell script "mount -t smbfs /

set Mounted to true

end timeout

end if

end try

end tell

return Mounted

end MountedSuccessfull

very interesting that Apple has not bothered to fix this constant authentication prompting as of yet ? or have they done so in the latest sierra beta 5 ?

So this is quite interesting, not only because lots of people are having the same issue as I found, but also that there are so many ways to mount a network share in macOS! Amazes me that people have been complaining about how awkward it is compared to Windows yet we still don't have a simple method to do this.


Anyway, I digress; I have a simple shell script that also stopped working with Sierra and I found the same workaround of mounting to my home folder to work, however I'm finding that after waking the mac from standby all the network drive icons have changed to the standard HDD icon and all of them are named "Macintosh HD". They're completely empty if I open any of then and they cannot be ejected. If I re-run the script then the spurious drives disappear and the normal network drives re-appear. Definitely didn't have this on any OS until Sierra.


Anyone else had this? Script below for reference, it's not pretty but it works!


#! /bin/sh
if [ ! -d ~/Mounts/itunes ]
then
  mkdir ~/Mounts/itunes
fi


if [ ! -d ~/Mounts/Software ]
then
  mkdir ~/Mounts/Software
fi


if [ ! -d ~/Mounts/Photos ]
then
  mkdir ~/Mounts/Photos
fi


if [ ! -d ~/Mounts/Movies ]
then
  mkdir ~/Mounts/Movies
fi


if [ ! -d ~/Mounts/Household ]
then
        mkdir ~/Mounts/Household
fi


if [ ! -d ~/Mounts/NAS_Home ]
then
        mkdir ~/Mounts/NAS_Home
fi


if [ ! -d ~/Mounts/Dropbox ]
then
        mkdir ~/Mounts/Dropbox
fi
if [ ! -d ~/Mounts/Lightroom ]
then
        mkdir ~/Mounts/Lightroom
fi
mount_afp afp://username:password@10.0.0.3/Music ~/Mounts/itunes
mount_afp afp://username:password@10.0.0.3/Public/Software ~/Mounts/Software
mount_afp afp://username:password@10.0.0.3/Photos ~/Mounts/Photos
mount_afp afp://username:password@10.0.0.3/Videos ~/Mounts/Movies
mount_afp afp://username:password@10.0.0.3/Public/Household ~/Mounts/Household
mount_afp afp://username:password@10.0.0.3/homes/username ~/Mounts/NAS_Home
mount_afp afp://username:password@10.0.0.3/homes/admin/Dropbox ~/Mounts/Dropbox


osascript -e 'tell application "Terminal" to if not ((count windows) > 1) then quit'