Batch file size tagging

I made an Applescript at work awhile back that would go through a folder of files and tag them with red dots if their file name exceeded 27 characters as I had to keep them no larger than 31 characters (including the dot 3 extension) at the time.

Because it could parse through all the files, I could do all kinds of things to the 3 file types (Photoshop, Illustrator and Canvas 9) that I used at work. I basically dbased each one of the various files in a Filemaker Pro dbase, got each file printed, and then copied each to a temp folder on a mounted Windows share.

----this script checks all the files in the STOCK FOLDER and if there are no problems, they all get filed, dbased and printed.
–label index numbers; 1 = orange, 2 = red, 3 = yellow, 4 = blue, 5 = purple, 6 = green, 7 = gray

tell application "Finder"
	activate
	set all_files to every file of folder "STOCK FOLDER" of folder "Desktop" of folder "<your username>" of folder "Users" of startup disk
	--returns list of files in the STOCK folder
	repeat with source_file in all_files
		set file_name to name of source_file
		set count_char to count characters of file_name
		if count_char is greater than "27" then
			set label index of source_file to 2
		end if
	end repeat
	delay 1
	beep 2
end tell

Hi 7k48r3s.

Strictly speaking, count returns an integer, not text. So the comparison should be:

if count_char is greater than 27 then -- not "27"

It doesn’t make any practical difference in your script because the text is on the right of the is greater than operator and is therefore automatically coerced to the class of the object on the left for the comparison:

9 is greater than "27" -- = 9 is greater than 27 --> false

But if, for instance, you’d expressed the comparison with the “27” on the left, the integer on the right would be coerced to text and the action would be:

"27" is less than 9 -- = "27" is less than "9" --> true

… unless of course the comparison’s in a considering numeric strings statement. But that’s getting unnecessarily complicated. :wink:

As this topic’s about offered code rather than a query, I’ve moved it to “Code Exchange”.

Thanks for the corrections. :+1: