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

Hi


I'm new to apple, but have a rudmentary programming background, and I'm trying to get the script to work with no joy ..

I have created the following script but nothing happens when I run it - other than the running icon for 50 seconds?

Is there anything else I need to set in the apple environment for it to run - I have a Macbook air 2014

Presumably it should create, and I should see, mount points in the named directory


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 "T******" -- 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("Music") then set NrMounted to NrMounted + 1

if MountedSuccessfull("TV Series") then set NrMounted to NrMounted + 1

if MountedSuccessfull("New") then set NrMounted to NrMounted + 1

if MountedSuccessfull("Videos") 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 "Media:password"

set NASIP to "Office-PC"

set MountPointFolder to "/Users/julieanne/Media/" -- I have created this directory in Finder

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 presumably 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 //" & serverAddress & " " & mountPoint
set Mounted totrue

end timeout

end if

end try

end tell

return Mounted

end MountedSuccessfull

I played around with that and it is just a setting issue inside the keychain. For a saved login you set the privilidges for direct access per program. So if you just add the Finder to the list of programs that may access the specific keychain entry without asking you it should work.

Same for Applescript, when you want to mount a share via Script. You just add the Finder (/System/Library/CoreServices/Finder.app) to the trusted apps for a login and in your AppleScript you just make sure that the mount-command is wrapped in an tell app "Finder"-statement


Maybe that screenshot explains better what I mean ;-)


https://www.apfeltalk.de/community/attachments/bildschirmfoto-2016-10-27-um-00-00-23-png.138953/

I've solved this in a kludgy way - with an applescript that ensures the login window has focus, and sends an enter keypress to the login window.


Save applescript as an application and at to your login items in Users and Groups under System preferences. Adjust the delay to suit


delay 5

tell application "System Events" to tell process "NetAuthAgent" to perform action "AXRaise" of window 1

tell application "System Events" to key code 36



You will need to add the application containing the script to the accessability list under System Preferences / Security and Privacy to grant it access to control your computer

I found a very simple solution for this problem by chance. I just put the server icon (keychain must be saved before) to my dock menu (on the right side). So all servers attached to the dock (keychains saved) will automount without any password confirmation.

Wow! This worked -- and so easy!

But what would the command be to unmount that same volume? I need to mount it (works), do something and then unmount it again, all scripted.

Many thanks in advance!

Thank you so much for this solution. I have been trying to find a perfect solution to mounting a network drive at login and this is the best one yet. I have been so frustrated having to enter the same username and password over and over. For some reason it never remembered my credentials and now it does.


Thank you.

Yes I can confirm this works... you have to use the IP adres of the shares... not the existing links you have been using so far...

But to anyone experiencing this issue, I do not really mind the password question, however the first drive I try to mount via the script gets duplicated under "volumes".


My script:

tell application "Finder"
  try
  mount volume "afp://TS431(AFP)._afpovertcp._tcp.local/Documents"
  mount volume "afp://TS431(AFP)._afpovertcp._tcp.local/Music"
  mount volume "afp://TS431(AFP)._afpovertcp._tcp.local/Video"
  mount volume "afp://TS431(AFP)._afpovertcp._tcp.local/Photography"
  end try
end tell


Now when it runs, it immediately creates a "documents" folder in /Volumes/

Then it asks my password and then connects the drives. However, because "Documents" is already there, it creates the 'real' drive on "Documents-1". When I then disconnect the drives and connect them again via the script, they create a "documents-1" and "documents-2". This changes the path of the drive which gives me problems with applications that do not know the updated path.


The weird thing is that when I do connect manually via finder this does not happen although it still asks for the password.


Any ideas how to solve that?

you can try to unmount the documents-volume, before you try to mount it again.


but there is an original-(apple-)"documents" folder in your User-Folder, so, it could be useful, to rename your network-folder to "mydocuments"....

i tweaked my applescript to klick the dialog box button by spawning a second applescript via shell right before my first (main) script issues the mount command - like this:


do shell script "

osascript -e 'delay 2 -- initial wait period until the server login/password box appears

tell application \"NetAuthAgent\" to activate

tell application \"System Events\" to keystroke return

delay 1 -- secondary wait period until the volumee chooser box appears

tell application \"NetAuthAgent\" to activate

tell application \"System Events\" to keystroke return' > /dev/null 2>&1 &"


very important: the "> /dev/null 2>&1 &" allows the "main" applescript to continue before the shell applescript ends, thus allowing two scripts to run in parallel

How do you add the server icon to the dock menu (what are the steps to do this)…maybe I'm making this more complicated that it is?

I get the same error using the mount_afp command. Figure that one out yet?


I also get the following error when trying to use the mount smbfs command as well:

error "usage: mount [-dfruvw] [-o options] [-t external_type] special node
       mount [-adfruvw] [-t external_type]
       mount [-dfruvw] special | node" number 1


Any ideas?

Open a Finder window, click on a network share (icons on the left).

Right-click on the Finder window title (over the name of the network share) and click below it on 'Network' (this is the parent folder, containing all network servers).

Now you have the server icon, which you can drag to your dock.

At least for me, this trick does not avoid the system asking for credentials for the first time! But it speeds up greatly the server discovery & connection to shares. Thanks!

Sounds very reasonable – but doesn't change the situation under Sierra (clickable mount-dialog appears).