Mmmmm. I wondered. I was sure that aliases COULD distinguish between two volumes with the same name. An experiment is in order. Here's the script ...
on run
set test1 to alias "Work_Files:test-1.sparsebundle" -- disk name = "testDisk"
set test2 to alias "Work_Files:test-2.sparsebundle" -- disk name = "testDisk"
set test1disk to my mountImageDisk(test1)
set test2disk to my mountImageDisk(test2)
delay 3
tell application "Finder"
eject test1disk -- the CORRECT disk is ejected
end tell
end run
on mountImageDisk(imageFileAlias)
tell application "Finder"
set desktop shows external hard disks of Finder preferences to true -- so the icon is visible on the desktop
open imageFileAlias
end tell
set posixPath to (POSIX path of imageFileAlias)
if last character of posixPath is "/" then set posixPath to (text 1 thru -2 of posixPath)
repeat -- while Finder mounts the disk
try
delay 1
set imageInfo to (do shell script "hdiutil info")
set AppleScript's text item delimiters to {posixPath}
set imageInfo to (text item 3 of imageInfo)
set AppleScript's text item delimiters to {"/dev"}
set imageInfo to (text item 2 of imageInfo)
set AppleScript's text item delimiters to {tab & "/Volumes"}
set imageInfo to (text item 2 of imageInfo)
set AppleScript's text item delimiters to {return}
set volName to ("/Volumes" & (text item 1 of imageInfo))
exit repeat
end try
end repeat
set diskAlias to (POSIX file volName) as alias
do shell script "mdutil -i off " & (quoted form of (POSIX path of diskAlias))
return diskAlias -- an alias to the disk mounted from the disk image file
end mountImageDisk ------------------------------------------------------
And, the result is that aliases DO distinguish disks with the same name.