- 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