Synology NAS tip | Create a custom Apple script to mount network shares on macOS


To make accessing network shares on our Synology NAS a breeze, we’ve come up with a clever solution. We’ve created an Apple Script that automates the whole process of mounting network shares.

While this script was originally meant for when we worked remotely on a VPN connection. We actually prefer to use it when we access our network shares, instead of having to hunt for them through Finder. So, we thought it might be a helpful tool for you too, so we’re sharing our code with you!

Note: Apple Script is a scripting language developed by Apple. It is specifically designed to automate tasks and control applications on macOS. With Apple Script, users can write scripts that can manipulate and interact with various software applications, including the ones developed by Apple. So a script can be used to automate repetitive tasks, streamline workflows, and enhance productivity on your computer.

  • Open Launch Pad and select Other.
  • In Other choose Script Editor.
  • Now copy and paste the following code into Script Editor.
try
	-- (1) check server's response
	set max_retry to 1
	set k to 0
	repeat while (do shell script "ping -o -c 1 enter-address-of-your-NAS") contains "100% packet loss"
		delay 0
		set k to k + 1
		if k > max_retry then error "Server is not responding for predefined period." number 8000
	end repeat
	
	-- (2) mount server volume
	
	tell application "Finder"
		
		activate
		
		set desktop shows connected servers of Finder preferences to true
		
	-- (3) displays list of network shares to mount
		try
			mount volume "smb://enter-address-of-your-NAS"
			
			display notification "The network share you requested is now available." with title "{NAS-Name} network shares"
			
		end try
	end tell
	
on error errs number errn
	
	display notification "Drive mount Failed. Please check your network connection and try again!" with title "{NAS-Name} network shares"
	
end try
  • Edit the highlighted parts of the code. This includes the notification messages which are between quote marks. 

Note: As Server Message Block is probably the most commonly used network file sharing protocol. We make reference to SMB in our script. However if you use Apple File Protocol (AFP) or Network File System (NFS). Simply substitute any reference in the code from SMB, to the file sharing protocol you use. 

  • Run your script to test that it works.
  • After confirming that the script works, you will need to turn it into a self executing application.
  • From the menu bar choose File – Export.
  • Change File Format to Application and choose Save.

Note: As you can recover your code from within the application you have created. You can delete the script file if you do not think you will want to amend or edit your code. However we prefer to keep both our script and our application save to a location on our computer. 

  • Move your new application to a safe location on your computers hard drive. 
  • Finally drag and drop your application onto the Dock of macOS so that you can easily run your new script.

Note: You might find that you want specific network shares to automatically open when you sign into your computer. So you can either amend the Apple Script that connects to your network shares, or configure your computer to mount specific network shares at sign in.

Add comment

Your email address will not be published. Required fields are marked *

Our site members

Thank you

Support This Site

If you enjoy our content but don't want to be a site member. Please consider supporting us on Ko-fi to keep us ads free. Thanks for all your support