I know I can mount Samba share using either mount or open command from the terminal shell. See this related question: How can I mount an SMB share from the command line?. I prefer using open because it mounts the shared folder under /Volumes which seems kind of OS X standard, the expected thing. Namely this happens by typing

open "smb://guest:@${host}/${path_component}"

(where ${host} is the host name or IP address of the Samba share and ${path_component} is the path or "name" of the Samba share). The result and the main thing is that I can access the stuff from /Volumes/${path_component}. This is very nice indeed. Just there are two problems or nuisance doing this from within scripts. The first is that this will open a superfluous progress indicator and then Finder window. The second, lesser one as there are scriptable work-arounds, is that the command returns immediately without waiting for the mount to be really available.

Is there a way to (synchronously) mount Samba shares under /Volumes without extraneous windows popping up?

(I am using the latest OS X (Sierra).)

up vote 8 down vote accepted

The following is what I use to mount Samba shares via launchd:

/usr/bin/osascript -e "try" -e "mount volume \"smb://guest@${host}\"" -e "end try"

Using osascript's mount means any keychain access needed is done "automagically", there's no progress indicator or Finder window, and the command waits for the mount to be available before proceeding (try it with && echo -n "Done."; mount appended to the end of the above command to test this).

  • 1
    OSA script? That's some weird stuff, but it works just like I want it to! Thanks! – FooF May 5 '17 at 10:29
  • @FooF osascript is the command line interface for AppleScript. – At0mic May 6 '17 at 0:17
  • Perfect. For shares needing authentication, you can replace smb://guest@$host with smb://username:password@$host in the above command. – mivk Jul 19 at 14:15

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.