Can I get Hazel to auto-prune some folders?

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

Moderator: Mr_Noodle

Can I get Hazel to auto-prune some folders? Sat Jun 28, 2014 2:48 am • by tiny-e
Scenario:

I have some folders that contain daily TV shows that I'd like to keep no more than 30 day's worth of episodes, and I have some folders that contain weekly TV shows that I would like to keep no more than 180 day's worth of episodes.

Folder structure like this:

TV Shows
+----Show 1 (lets say it's a daily show) [Finder Comment "Prune 30"]
+---- Some subfolders of Show 1

+---- Show 2 (let's say it's a weekly show) [Finder Comment "Prune 180"]
+---- Some subfolders of Show 2

+---- Show 3 (archiving all, no pruning needed) No Finder Comment

I'd like hazel to enter the folder TV shows, prune the contents of the Prune 30 and Prune 180 folders (chucking files older than 30 and 180 day's respectively)

But not prune anything else --unless the Finder comment says to.

Is this possible? I've been mucking around without a ton of luck so far.
tiny-e
 
Posts: 22
Joined: Fri Mar 12, 2010 5:51 pm

Can't you just do "If Domment is Prune 30 and Date added is not in the last 30 days" (and likewise for Prune 180)?
Mr_Noodle
Site Admin
 
Posts: 11868
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Can I get Hazel to auto-prune some folders? Mon Jun 30, 2014 11:27 am • by tiny-e
Mr_Noodle wrote:Can't you just do "If Domment is Prune 30 and Date added is not in the last 30 days" (and likewise for Prune 180)?


I think the problem I'm having is that they're all folders inside my "Tv Shows" folder. I was trying (in this order)

  • Recurse folders if comment is "PRUNE 30"
  • Delete any empty folders
  • Move any files more than 30 days old to the trash, wait a few secs, empty trash
  • Recurse folders if comment is "PRUNE 180"
  • Delete any empty folders
  • Move any files more than 180 days old to the trash, wait a few secs, empty trash

I'm guessing the 30 day rule is firing on the files when it enters the 180 day folders. The individual files aren't commented.

I can make this work as I'd like on a per-show/folder basis, but am trying to make it so when I add/set up a new show, I can just enter "PRUNE YADA" in the Finder comment and have Hazel do the rest.
tiny-e
 
Posts: 22
Joined: Fri Mar 12, 2010 5:51 pm

Since the first rule to match "wins", try reversing the order of those rules.
Mr_Noodle
Site Admin
 
Posts: 11868
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle wrote:Since the first rule to match "wins", try reversing the order of those rules.


I was wondering if I should do that.. need to go in and make a non-destructive version to verify it works...
tiny-e
 
Posts: 22
Joined: Fri Mar 12, 2010 5:51 pm

I know it's thread necromancy, but I think I've got it:


Remove Empty folders
If kind is folder and size is less than 1MB send to trash.
-----------------------------------------------------------------------------------------

Find 180:
If all of the following conditions are met:
If kind is folder and comment is "Prune 180"
Run rules on folder contents.

Prune 180:
If all of the following conditions are met:
Date Added is not in the last 180 days
Kind is not Folder
Color label is not "Green" (I use this to save things I don't want pruned)

Move to folder "Trash"
Set color label to "Red"

-----------------------------------------------------------------------------------------

Find 90:
If all of the following conditions are met:
If kind is folder and comment is "Prune 180"
Run rules on folder contents.

Prune 90:
If all of the following conditions are met:
Date Added is not in the last 90 days
Kind is not Folder
Color label is not "Green" (I use this to save things I don't want pruned)

Move to folder "Trash"
Set color label to "Red"


-----------------------------------------------------------------------------------------


Rinse and repeat for other amounts of days, --in descending order.
tiny-e
 
Posts: 22
Joined: Fri Mar 12, 2010 5:51 pm

Re: Can I get Hazel to auto-prune some folders? Sun Jun 21, 2015 11:45 pm • by tiny-e
Sigh...

It's not working... at least not right. Here's what's happening:

These are folders containing TV shows arranged like this TV Shows/Show Name/Season XX/Episode name.ext
Some shows don't have subfolders as they're "Daily" type shows, in those shows hazel enters and does its thing --but it rips through all the pruning rules, so if I have rules set for 90, 60, 30, 14 days and it entered on a folder commented to "Prune 60" it would run all rules and wipe out all shows not added in the last 14 days.

If it hits a subfolder (like "Season 01") it doesn't recurse the folder. Which is probably good because Hazel would have trashed a bunch of stuff it shouldn't have.

Hazel needs a function (imho) that says "Run this specific rule and stop".
tiny-e
 
Posts: 22
Joined: Fri Mar 12, 2010 5:51 pm

I'm not sure if I follow here. By default, only one rule is executed per folder/file that matches it. There must be something else in the structure of your rules if it's causing it to cascade the way you are saying.
Mr_Noodle
Site Admin
 
Posts: 11868
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Folder structure is TV shows/show name/season/file name.mkv

Rules are being run on TV shows folder, they are
Find 90 -finds folders with comment "prune 90", runs rules on contents
Prune 90 - deletes files whose date added is not within the last 90 days
Find 60
Prune 60
Find 30
Prune 30
... And so on

The shows that I want to prune have a finder comment like "Prune 30" in the "show name" folder. Inside the "show name" folder, almost always, are season folders containing episodes (I can change this to a flatter structure with a click if I need to)

Hazel is not entering the sub folders. So things are piling up.

Some shows don't have season folders (air by date shows) and hazel definitely enters their parent folder ("show name") but then executes all pruning rules. So if the comment was "prune 90" hazel would do that .... And then do all the other prune rules too :(
tiny-e
 
Posts: 22
Joined: Fri Mar 12, 2010 5:51 pm

Looking at your rules again, I don't think your rules work like you think. You don't want to go into a folder unless both the comment is there and that it has folders that need pruning according to the age. Once it goes into the folder, it doesn't know what folder it's in so it just prunes. The rule that actually prunes instead needs to have some way of knowing which prune mode (180/90/etc) it's in. You can do try something using a nested condition (search the forums for it) and applying conditions to the enclosing folder.
Mr_Noodle
Site Admin
 
Posts: 11868
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I want it to enter the folders with the comments and then apply the appropriate rule to the files in the folder (or in subfolders) of that folder.

I've been trying to figure this out (off and on) for a long time. Having this functionality would endear Hazel to cord-cutters.


I'm a paid licensee... Maybe if you know how I could accomplish this, you could tell me (or spell it out a little better)? Documentation is sparse. The file / folder structure is the default for pretty much all HTPC setups

Thanks
tiny-e
 
Posts: 22
Joined: Fri Mar 12, 2010 5:51 pm

The problem is that the rule to prune doesn't know which folder it is in. For instance, the prune 60 rule doesn't know it's in a "60" folder or not so it will fire when in any folder. You need to add a nested condition as follows:
Code: Select all
    If (all) are met
        If (all) are met for (the enclosing folder)
            Comment is "Prune 60"
       ...


To get the nested condition, hold down option while clicking the + button to create a new condition. Note that this only works for one level deep. If you want Hazel to go deeper then it gets much more complicated.
Mr_Noodle
Site Admin
 
Posts: 11868
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Can I get Hazel to auto-prune some folders? Mon Jul 06, 2015 12:19 am • by tiny-e
Mr_Noodle wrote:The problem is that the rule to prune doesn't know which folder it is in. For instance, the prune 60 rule doesn't know it's in a "60" folder or not so it will fire when in any folder. You need to add a nested condition as follows:
Code: Select all
    If (all) are met
        If (all) are met for (the enclosing folder)
            Comment is "Prune 60"
       ...


To get the nested condition, hold down option while clicking the + button to create a new condition. Note that this only works for one level deep. If you want Hazel to go deeper then it gets much more complicated.


I think this (combined with flat folder structure) does it. Thank you :)

I'm curious to know how to deal with a non-flat file structure for something like this. I'll search around, but if you know of / can point me to an example, I'd appreciate it.
tiny-e
 
Posts: 22
Joined: Fri Mar 12, 2010 5:51 pm

You'd either have to do some system where you trickle down, via a tag or comment, the name of the folder and use that, or use a script to walk up the folder tree to the folder you want.
Mr_Noodle
Site Admin
 
Posts: 11868
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support

cron