Assigning color to a file based on its extension

I’ve wrote this little script to find files based on their extension.

If so, I am doing two things:

  • move them to a specific folder;
  • assign a color based on the extension

The script does not work for assigning a color I get the following error message : Can’t set “class labi” of {} to 3.

Would anyone have an idea why this script is not working?

With regards!
Daniel

my VerifyConvertedFiles((path to home folder as text) & "FPAQ:WVCUfiles:", "mp4", 3)
my VerifyConvertedFiles((path to home folder as text) & "FPAQ:WVCUfiles:", "avi", 4)

on VerifyConvertedFiles(WVCUDestinationFolder, theFORMAT, ColorNumber)
	tell application "Finder"
		set theCardFiles to files in folder WVCUDestinationFolder whose name extension is theFORMAT
		set theFile to files in folder WVCUDestinationFolder whose name extension is theFORMAT
		tell application "Finder" to set label index of theFile to ColorNumber
	end tell
	
	if (count of theCardFiles) is equal to 0 then
		display dialog "No " & theFORMAT & " have been found"
		return
	end if
	display dialog theFORMAT & " have been found"
	my MoveConvertedFiles(theFORMAT)
end VerifyConvertedFiles

Well, “theFile” is a most inappropriate name for a list of things, and you are asking
the Finder to set the label of a list, which appears to be empty anyway.

To do what you want, you will need to loop through the (renamed) _file_list.

JD

path to home folder as text

Are your files at the top level of the home folder?
Maybe you have an empty list because there are no files with the wanted extension there!

Hello.

As mouramartins suggests, your filelist seems to be emtpy.

try this, to get a closer look of your folder definition:


set probe to (path to home folder as text) & "FPAQ:WVCUfiles:"
log probe