Mount NAS Share

I mount NAS shares via smb on my Mac. I have been using 'open URL' to do this but now [os 10.14.2] I keep getting prompted for the user name and password even though I have stored it in my keychain.

Is there a better way to mount the share other than 'open url'?
Any help?

Yeah, macOS is getting increasingly annoying about mounting network drives, and I don't understand why. Even in High Sierra there are many times when I found myself having to click "Connect" and then "OK" when it asked me if I wanted to connect.

Here's some shell script / AppleScript code that you should be able to adapt. It was originally based on me trying to mount my Time Capsule drive, but it should work for any NAS-type drive.

The first thing to do it open and run the mount command, to see what format it uses for the mount point.

For me it was something like this:


But for you it will probably be different. Be sure to replace what I have below with whatever is correct for your system.

Secondly, in order to avoid putting your password in Keyboard Maestro or a shell script, use the security command which uses the macOS Keychain feature.

First, add the password to your keychain like this:

security add-generic-password -a MyNA -l MyNAS -s MyNAS -w "mYSecKretPA$$Word"

Where "MyNAS" is whatever you want to call your NAS drive, and where "mYSecKretPA$$Word" is your actual password for connecting to your NAS. Make sure it doesn't have any quote marks (") in it. Otherwise you're just asking for trouble.

Then put this script into Keyboard Maestro with whatever trigger you want to use to mount your NAS drive:

#!/bin/zsh -f 

## This will retrieve your MyNAS password fro the keychain. Be sure to use whatever you used
## instead of "MyNAS" when using 'add-generic-password' above!! 

NAS_PASSWORD=$(security find-generic-password -a 'MyNAS' -s MyNAS-g 2>&1 \
| awk -F'"' '/^password/{print $2}')

# Don't Indent - BEGIN
/usr/bin/osascript <<EOT 1>/dev/null
	mount volume "afp://Timothy%20Luoma@TimeCapsule._afpovertcp._tcp.local/TimeCapsuleDisk" with password "$NAS_PASSWORD"
end try
# Don't Indent - END

Again, be sure to replace the stuff after "mount volume" with whatever the mount command showed as correct for your NAS drive.

I hope this helps. Let me know if you need clarification.