Change folder colour...

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Change folder colour... Mon Jan 17, 2011 7:48 pm • by stephmoreland
I've got a bunch of folders in my downloads folder where I separate files by extension so I can weed through them at a later date.
I'm trying to make Hazel change the folder colour, or label colour if there are files in that folder. So if there are files, the folder is red, and if there aren't files in the folder, it's back to normal. That way, I can see at a glance if there are files that I need to deal with.
So far, I haven't had any luck, I can't seem to find a way to target a folder; I can target all the files, but not the folder.
stephmoreland
 
Posts: 1
Joined: Mon Jan 17, 2011 7:42 pm

Re: Change folder colour... Tue Jan 18, 2011 12:04 am • by dhy8386
Here it is in the easiest, flexible form. I think this works. You can make this more complex if you want different folder colors for different extensions.

Add the Downloads folder to Hazel.

Then set up the following rules on the Downloads folder in THIS order or it wont work:

1)
If all conditions:
Size is less than 1KB
Then:
Set Color label to blank (the "x")

2)
If all conditions:
Kind is Folder
Then:
Run Rules on Folder contents

3)
If all conditions:
Any File [here instead of Any File you could specify extension types]
Then:
Run Applescript embedded
Code: Select all
tell application "Finder"
   set posix_parent_dir to POSIX path of (container of (item theFile) as text)
   
end tell
return {hazelSwitchFile:posix_parent_dir}

Set Color label to Red

The first rule basically is looking if the folder is empty - where the size is 0KBs but to be safe i said less than 1KB since i cant imagine you have a file thats small you are downloading. If there is a file in the folder than the rule will be false and move on to rule 2. Rule 2 tells hazel to run the rules on the folders contents. This is how you get Hazel to act on files in folders. The third rule says simply if there is any file present then run he applescript which tells hazel to retarget the parent folder (as opposed to acting on the file in the folder) and the set its color to Red.

Now you could simply just run size rules on folders - if less than 1KB no color if greater than 1KB color Red. However, i set up the rule to allow you to have finer granularity should you want to target certain extension types and set folder colors based on that...your call.

Let me know how it works.
dhy8386
 
Posts: 96
Joined: Tue Nov 09, 2010 12:19 pm

Re: Change folder colour... Tue Jan 18, 2011 12:09 pm • by Mr_Noodle
There is also a Spotlight attribute called "Number of items". Using that, you can do a rule like:

If Kind is folder and number of items > 0, color file...

Note though that this count may include invisible files (like those pesky .DS_Store files). Play with it and see if it works for you.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Change folder colour... Mon Feb 13, 2017 11:48 pm • by patjbrown1983
This is great - but is there a way to tell the applescript to go up 2 or 3 parent directories, before changing the label colour?

I have the same question, but I dont want to change the colour of the direct parent, rather 3 parents up.


dhy8386 wrote:3)
If all conditions:
Any File [here instead of Any File you could specify extension types]
Then:
Run Applescript embedded
Code: Select all
tell application "Finder"
   set posix_parent_dir to POSIX path of (container of (item theFile) as text)
   
end tell
return {hazelSwitchFile:posix_parent_dir}

Set Color label to Red
patjbrown1983
 
Posts: 4
Joined: Mon Jan 30, 2017 8:48 pm

Re: Change folder colour... Tue Feb 14, 2017 1:00 pm • by Mr_Noodle
This thread is very out of date.

First read this: https://www.noodlesoft.com/kb/how-to-cr ... onditions/

There, you'll see a new pop-up indicating the target for conditions under it. You can set that to "any" or "all" sub-files. Conditions under that will apply to sub-files of the folder you set to match that rule. Any conditions outside of that nested condition as well as all actions still apply to the folder.

In short, it provides a way to match and act on a folder based on its contents.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support