Delete file based on label color

I have a folder full of files all with blue color labels.
I’m trying to find a script that will delete a file if it’s label color is set to anything other than blue.

Is this possible?? If so, any help would be appreciated.

Thanks
lghtguy

Hi lghtguy,

try this:

set theFolder to choose folder
tell application "Finder" to delete (every file of theFolder whose label index is not 4)

Thanks a lot for the script.

I’m extremely new to applescript and am having a hard time with it.

What I would love is a script that I could attach as a folder action to my folder so that if a file’s label color is changed from blue it automatically deletes it with no input or action from me.

Any help would be greatly appreciated.

Unfortunately this is not possible directly, because there is no folder action, which checks whether a label color has been changed.

You can use a script saved as application with stay open option, which checks periodically the folder

property theFolder : "Macintosh HD:Users:MyUser:MyFolder"
on idle
	tell application "Finder" to delete (every file of folder theFolder whose label index is not 4)
	return minutes -- checks every minute
end idle

or a folder action which triggers the script, when item(s) are added to the folder

on adding folder items to thisFolder after receiving theseItems
	tell application "Finder" to delete (every file of thisFolder whose label index is not 4)
end adding folder items to