I have the following to identify if a volume is mounted:
on volumeMounted:aNotification
set volumeName to (NSWorkspaceVolumeLocalizedNameKey of aNotification's userInfo) as text
if volumeName is "myVolume" then
--do something
end if
end volumeMounted:
on volumeUnmounted:aNotification
set volumeName to (NSWorkspaceVolumeLocalizedNameKey of aNotification's userInfo) as text
if volumeName is "myVolume" then
--do something
end if
end volumeUnmounted:
I wanted a way to identify if an external volume is mounted even though it has the same name.
For example: my internal volume is named "Macintosh HD" and I connect an external volume with the same name it is only recognizing 1 volume, so I can't unmount both volumes with a Button created in the Interface.
Note: I know I could just right click and ask to eject but I wanted to do that in the UI.
There is another key
NSWorkspaceVolumeURLKeyin theuserInfodictionary of thevolumeMountednotification .The associated value is the URL of the mount point. You can cast the URL to
alias. The default folder for mounted volumes is/Volumes, the path of the startup volume is always/.