MountNAS

MountNAS

This AppleScript mount's all NAS volumes if they are not already mounted, if they are mounted they will be ejected.

To make this script a stand-alone app, just export it as an application from the Scrip Editor (part of macOS)

Usage

You need to change some variables to reflect your environment:

nasName - NAS name or IP-address
shareList - A list of Volumes to be mounted
nasIP - the IP-adress of the NAS

Image

The Script Source Code

-- Mount/Unmount all my NAS drives
-- Assumes user and password is stored in the Keychain

-- By Michael Augustsson

-- Version 1.0 2018-05-17 - Initial release
-- Version 2.0 2018-05-18 - Rewrote to loop through the shares, and if mounted unmount the drive

set nasName to "DISKSTATION"
set shareList to {"FileServer", "Bilder", "music", "video"}

set nasIP to "10.0.1.7"
set pingCount to 1
set pingTimeout to 10

tell application "Finder"

-- First try to ping the NAS to make sure it is alive and we are on the same network
try
-- ping to see if the nas is online
do shell script "ping -c" & pingCount & " -t " & pingTimeout & " " & nasIP
on error
-- we just return
return
end try

-- mount each share from the array if not mounted
repeat with a from 1 to length of shareList
set shareName to item a of shareList
if not (disk shareName exists) then
try
mount volume "smb://" & nasName & "/" & shareName
on error
-- do nothing if we where not able to mount the share
end try
else
-- The share was mounted, then unmount it
eject disk shareName
end if
end repeat

end tell


© 2018-2020 Michael Augustsson Contact Me

improve your online experience. Take a look at the Cookie Privacy to learn more and also my Privacy Policy. By pressing Dismiss I assume you are happy to allow the use of these cookies.

RapidWeaver Icon

Made in RapidWeaver