macosmountautomatorsmb

Error dialog when using Mac Automator to mount/connect SMB shares that are already mounted/connected


I'm using Automator (on a Mac running OS 10.10) to mount three SMB shares on login. It works well. However, sometimes one or two of the shares can get disconnected. When I run my custom Automator application again (via an icon I placed in the dock), I get an error dialog (because some [or all] of the SMB shares I'm trying to mount are already mounted).

Dialog box image: http://s30.postimg.org/m8rud8d1d/Screen_Shot_2014_11_05_at_10_38_04_AM.png

How do I stop this from appearing?

Also, say 2 of my 3 shares are mounted, and I'm trying to use the custom Automator application I made to mount the third and last share; it won't. So I have to manually disconnect the other 2 shares, and then run my custom Automator application, and all 3 shares will mount as intended.

Is there a way in Automator to check if a share is already mounted? And if so, skip mounting that share?


Solution

  • I've run into the same problem when I added Get Specified Servers followed by Connect to Servers Automator actions to my workflow and I assume you've been using the same pair to connect to Samba shares.

    If this is the case you might want to opt for the Run AppleScript action with a piece of AppleScript code instead. This code snippet works for me on OS X 10.10.3:

    on run {input, parameters}
      tell application "Finder"
        try
          mount volume "smb://Guest:@<hostname>/<share>/"
          delay 1
        end try
      end tell
      return input
    end run
    

    This action shouldn't cause any issues with the existing workflows as it seamlessly passes its input to the output in its current form.

    If you need a more robust solution, e.g. check if network shares are actually available prior to attempting to connect to them, you might want to refer to this answer on Apple StackExchange and an extended and more defensive version of the code above that's been provided by Jason.