Differentiating by Kind

Hello all,

I’m sorry for asking what I imagine is a pretty basic question. I’ve looked for the answer in several sites and had no luck.

I’m curious how to make a script that can do various things to files/folders/disks based on what the object is. Specifically I’m trying to make a script that will take a selection of multiple things(disks and files), and eject the disks and move the files to the trash. I have this:

tell application "Finder"
	set thestuff to selection
	
	repeat with i from 1 to the number of items in thestuff
		
		set this_item to item i of thestuff
		
		if the kind of this_item is disk then eject this_item --I know this is bad/wrong
		if the kind of this_item is file then move this_item to the trash --I know this is bad/wrong

	end repeat
end tell

I don’t know how to make applescript get the kind of an item. Is what I’m trying to do possible?

Many thanks,

Casey Koons

Model: iBook G4
AppleScript: 1.10.3
Browser: Firefox 1.5.0.1
Operating System: Mac OS X (10.4)

Hi, Casey.

You’re looking for the ‘class’ of each item in this case. Also, you need an ‘if … else …’ construction so that the checks don’t continue after the object’s identified. (If you find a disk, say, and eject it, you don’t then want to check this no-longer-existent item to see if it’s a file!)

tell application "Finder"
	set thestuff to selection
	
	repeat with i from 1 to (count thestuff)
		
		set this_item to item i of thestuff
		
		if the class of this_item is disk then
			eject this_item
		else if the class of this_item is file then
			move this_item to the trash
		end if
	end repeat
end tell

Thanks so much!!