Choosing a drive name

Hello.

The following handler gets a list of the name of the disk drives that the user usually accesses in order to choose the name of the desired disk drive.

on chooseDisk()
	tell application "Finder"
		set userVolumes to (every disk whose local volume is true and ejectable is true and not (name contains "backup") and not (name contains "Timemachine") and not (name contains "data"))

		set volumeNames to {}
		set end of volumeNames to name of startup disk

		repeat with aVolume in userVolumes
			set end of volumeNames to name of aVolume
		end repeat
		
		set theDdisk to choose from list volumeNames with prompt "Choosing the disk drive: " with title "Disks"
	end tell
	
return theDdisk
end chooseDisk

However, I wonder if there is a better syntax for filtering other drives not accessible from Finder.
I am referring to the fragment“and not (name contains “backup”) and not (name contains “Timemachine”) and not (name contains "data”)”.

Thank you in advance.

All special disks belong to the root user so filter for not (owner is "system")
This applies also to the startup disk but you gather the name of the startup disk separately anyway.

on chooseDisk()
	tell application "Finder"
		set userVolumes to name of (every disk whose local volume is true and ejectable is true and not (owner is "system"))
		set startupDisk to name of startup disk
		set theDdisk to choose from list {startupDisk} & userVolumes with prompt "Choosing the disk drive: " with title "Disks"
	end tell
	return theDdisk
end chooseDisk

Thank you very much, StefanK, for your quick response.

Perfect the code simplification to concatenate lists instead of entering one by one the elements of a list in another list.

However the filter


“and not (owner is "system”)” 

does not act on the Timemachine disk and, above all, on a huge list of disks that are backups (.backup).

That’s weird.
Of course I tested the script and I have also Time Machine disks which are filtered because they are owned by system

DJUNQUERA. Stefan’s solution is best if it can be made to work for you. I don’t have any way to test Stefan’s script, though.

I edited Stefan’s script to include your original whose clause, and this seemed to work fine. The timing result on my Sequoia computer was 11 milliseconds.

chooseDisk()

on chooseDisk()
	tell application "Finder"
		set startupDisk to {name of startup disk}
		set userVolumes to name of (every disk whose local volume is true and ejectable is true and not (name contains "backup") and not (name contains "Timemachine") and not (name contains "data"))
	end tell
	set theDdisk to choose from list (startupDisk & userVolumes) with prompt "Choosing the disk drive: " with title "Disks"
	return theDdisk --a list with one item
end chooseDisk

If the goal is to eliminate the whose clause, the following will do that plus it’s a bit faster at 8 milliseconds.

chooseDisk()

on chooseDisk()
	set doNotMatch to {"backup", "Timemachine", "data"}
	
	tell application "Finder"
		set startupDisk to {name of startup disk}
		set userVolumes to name of every disk whose local volume is true and ejectable is true
	end tell
	
	--considering case --default is to ignore case
	repeat with aVolume in userVolumes
		repeat with aName in doNotMatch
			if aVolume contains aName then
				set contents of aVolume to missing value
				exit repeat
			end if
		end repeat
	end repeat
	--end considering
	
	set dialogList to startupDisk & text of userVolumes
	set theDdisk to choose from list dialogList with prompt "Choosing the disk drive: " with title "Disks"
	return theDdisk --a list with one item
end chooseDisk

My first intention was to make a filter by means of a repeat loop to separate those disks that had the not wished chains, but I did not know how to make it correctly.
For that reason, I chose to filter the names of the disks using the “contents” property, but it seemed to me that it was a sloppy solution, in spite of its good results.

Thank you very much for your help and for learning from your knowledge.

Thank you very much for your help and for learning from your knowledge.