Choose volume dialog box

There are choose file dialogs and choose folder dialogs, but what about a dialog to choose a volume (drive)? Thanks to the help from MacScripter (I’m beginner-medium experience) here is code to get a choose volume dialog box:


-- get a list of items in the Volumes folder (basically a list of mounted disks)
do shell script "ls /Volumes/"
-- set _Result to the list items
set _Result to the paragraphs of result
-- set theVolumeTemp to choose a volume from the list, result would be something like "Macintosh HD"
set theVolumeTemp to (choose from list _Result with prompt "Choose Volume:" without empty selection allowed)
-- if user presses Cancel, close the dialog
if theVolumeTemp is false then return
-- set theVolume to the actual path, e.g. /Volumes/Macintosh HD/
set theVolume to "/Volumes/" & theVolumeTemp & "/"

I’ve commented out the different parts, the final variable (theVolume) would return the full path to the volume e.g. /Volumes/Machintosh HD/, good for using in shell scripts. You could also modify the last line to replace the slashes with colons to use in an AppleScript only script.