10

For several OS X versions I've used:

/usr/bin/osascript -e mount volume "smb://yourserver" as user name  "yourusername" with password “yourpassword”

This has worked great, a nice and quiet mount of the network share, if it is available of course.

Now recently I installed macOS Sierra (10.12 public beta, build 16A238m), and the script still works, however it will now suddenly always show a login dialog, pre-populated with the "yourusername" and "yourpassword" values. The user will still have to click "Connect" to mount the share.

Does anyone know if this is a "bug" in the beta version (I did report this with Apple's Feedback app), or is this expected and/or what would be the "fix" for that?

See also: AppleScript Documentation "mount volume"

  • 3
    It could be related to the fact Apple have locked down the /Volumes folder where the network share is mounted to root access only, requiring user authorization to create the mount point. Unfortunately I don't know of a work around at the moment, though I'm going to play with modifying sudoers on the computer. I have an Open Radar at openradar.appspot.com/radar?id=4948585099558912 wheren Apple have confirmed it's locked down. – mattdwen Aug 16 '16 at 22:43
12

As Apple replied to the ticket referenced in mattdwen's Open Radar link above, as of macOS Sierra 10.12,

you can no longer create items in /Volumes unless root.

Further, my best understanding of the AppleScript mount volume command is that it doesn't have a way to specify the mount point and consequently it only mounts volumes under /Volumes through the Finder's standard mechanism. So, I don't think you can do it via AppleScript.

But there's another way. You can accomplish the same thing using the lower level mount command:

mkdir -p ~/mnt
mount_smbfs "//my_username:my_password@my_hostname/share" ~/mnt

After mounting the volume this way, you should see a normal "volume" icon appear on your desktop and the ~/mnt directory will appear as "share" when you browse your user directory via Finder.

The one thing missing from this approach is saving the login credentials in Keychain. To do that, you have to do a bit more scripting. Something like this.

Save the password:

security add-generic-password -a my_username -s my_hostname -w my_password

Retrieve the password and mount the share:

pass=$(security find-generic-password -a my_username -s my_hostname -w)
mount_smbfs "//my_username:${pass}@my_hostname/share" ~/mnt

NOTE: If you have special characters in your password, you will probably need to URL encode it, perhaps like this:

pass='my !@#%%^& password'
pass=$(php -r "echo urlencode(\"$pass\");")
>>> my+%21%40%23%25%25%5E%26+password
  • Thank you mnewt and mattdwen! This should be a good work around! (and possible a better one than using AppleScript) – Hanzaplastique Sep 23 '16 at 14:12
  • 4
    presumably this approach would break anything that references files under /Volumes/share? – Jack Sep 29 '16 at 10:38
  • It definitely would break anything like that. – Br.Bill Dec 16 '16 at 23:32
4

This has been fixed by Apple in macOS Sierra 10.12.2:

https://support.apple.com/en-us/HT207112

  • There is a typo in their "undo" example. The correct "undo" way would be: sudo defaults delete /Library/Preferences/com.apple.NetworkAuthorization AllowUnknownServers (removed the "write" in that line). – Hanzaplastique Dec 25 '16 at 17:03

You must log in to answer this question.

protected by Community Oct 25 '16 at 11:57

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged .