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)


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


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 ""
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
-- ping to see if the nas is online
do shell script "ping -c" & pingCount & " -t " & pingTimeout & " " & nasIP
on error
-- we just 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
mount volume "smb://" & nasName & "/" & shareName
on error
-- do nothing if we where not able to mount the share
end try
-- 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