Check if a disk is mounted? (without unmounting then re-mounting)

I found a script that checks to see if network disks are mounted, and if not mounts them. I managed to get it to work with some disks of my own (a NAS disk connected to my AirPort Extreme, and some disks connected to a different Mac). Here’s an example of the script for one of the disks;



tell application "Finder"
	if not (disk "AirDisk 500GB" exists) then
		mount volume "afp://airport-extreme.local/AirDisk 500GB" as user name "myname" with password "mypassword"
	end if
end tell

But every time the script runs it and the disks are already mounted it unmounts the disks then mounts them again.
Is there any way to stop it from unmounting then mounting again when the script runs and a disk is already connected?

Hi,

thy this, it checks the folder /Volumes instead of the Finder disk objects

property myDisk : "AirDisk 500GB"

set mountedDisks to paragraphs of (do shell script "/bin/ls /Volumes")
if myDisk is not in mountedDisks then
	mount volume "afp://airport-extreme.local/" & myDisk as user name "myname" with password "mypassword"
end if

That works great, thanks!

How would I run this on more than 1 disk? E.g. disks named “AirDisk 500” and “AirDisk 320”

I tried below, but it didn’t work

property myDisk : "AirDisk 500GB", "AirDisk 320"

Thanks again.

You haven’t found this script :smiley:

What I do is using the shell:

  • It doesn’t have stupid Finder messages
  • It is very easy to change it for a NAS.
  • You don’t have to mount the volume in /Volumes folder (very usable for NAS volumes)
  • It checks if a volume is mounted or not

assuming each disk uses the same user name and password


property myDisks : {"AirDisk 500GB", "AirDisk 320"}

set mountedDisks to paragraphs of (do shell script "/bin/ls /Volumes")
repeat with aDisk in myDisks
	if aDisk is not in mountedDisks then
		mount volume "afp://airport-extreme.local/" & aDisk as user name "myname" with password "mypassword"
	end if
end repeat


Brilliant. Thanks again! :slight_smile:

That’s also handy, thanks.