Mounting a network share on macOS

Unfortunately, macOS still doesn't offer an option to automatically mount network drives, for example after restarting the system or when the Mac awakes from sleep. Of course there are some workarounds, like adding the mounted network drives to the startup items or running some shell scripts. But if you already happen to have Task Till Dawn installed on your system, you can just leverage this simple task. In addition, it's even possible to check whether the drive has already been mounted before so that mounting the drive again can be skipped.

Below you find two solutions, a simple one and an extended version. The latter shows how you can check whether the network drive has already been mounted or not.

What you need for the simple version

  1. Only the "Open URL" action is required

Setting up the workflow

Simply add the "Open URL" action to the workflow, and enter the URL of the network drive you want to mount. For example if it's an SMB share, enter an URL like "smb://fritz.box". Whenever you run the task the network share will be mounted in the Finder (if you haven't reassigned the protocol to be handled by some other application). The first time you mount the share it might be required that you enter your credentials. In this case make sure that you store these in the keychain, so you won't have to enter them everytime the share gets mounted!

Workflow mounting a network share on the Mac
Mounting a network share on the Mac using the "Open URL" action

What you need for the extended version

  1. The "Specify files and folders" action
  2. The "Filter files and folders" action
  3. The "Count list elements" action
  4. The "Open URL" action
  5. One jump label

Setting up the workflow

The first thing we need to do in this workflow is to check whether the network share has already been mounted before. Normally, macOS mounts all external volumes and network drives under the path "/Volumes". So if a folder exists underneath this path which matches the name of our network drive, we can assume it has been mounted an do not need to mount it again. To check if the folder exists, we first need to define its path using the "Specify files and folders" action. Add it to the workflow as the first action. If the network drive is currently mounted, select "Add folder" (by clicking on the "plus" button) and then select the mounted network drive in order to add it to the list. If it is not mounted at the moment, select "Add path" instead and manually enter the drive's path, like for example "/Volumes/FRITZ.NAS".

This results in a list variable "Specified files and folders" which contains exactly one entry – the path of the network drive just defined. Now we need to check whether this path actually exists. We can do this using the "Filter files and folders" action. Add it to the workflow and filter by "File or folder > exists". The action returns only elements which match the given filter. So if the specified Volumes-path does not exist it will return an empty list. By default, the result of this action is named "Filtered files and folders". We'll just keep it this way.

The next step is to check whether the "Filtered files and folders" variable is empty or not. Use the "Count list elements" action to do this. Ensure that the input of this action is set to "Filtered files and folders" – the output of the previous action. It not only counts the elements but also allows us to continue at a jump label if the list contains one or more elements. This is what we want to do. Add a jump label to the end of the workflow, name it "Workflow end" and select it in the "Count list elements" action. Set the condition to "is equal to" and enter a "1" as the value to check.

What we have now is a workflow which checks whether a folder in "Volumes" exists. If the folder exists, the workflow continues at the jump label "Workflow end". The last thing left to do now is to mount the network drive if the folder does not exist. We use the "Open URL" action like again, like in the simple version of this task. Add it to the workflow, directly before the "Workflow end" label and enter the URL for the network drive.

Extended workflow mounting a network share on the Mac
Mounting a network share on the Mac if it has not been mounted before

Comments (2)

  • «
  • »
  • «
  • »

Leave a comment, if you want to!
Marked fields (*) are mandatory.

Will not be published
By ticking this checkbox you agree to the storage of your data by this website. In order to be able to display comments this website stores the specified name, e-mail address, the specified website, the comment text as well as the time stamp. If you wish, you can have your comments deleted later. For detailed information, see my privacy policy.