Archive a year of monthly statements

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

Moderator: Mr_Noodle

Archive a year of monthly statements Wed Jun 03, 2015 12:29 am • by gwagener
I have a folder with recent and older bank statements in it. The contents look like
  • 2012.zip
  • 2013.zip
  • 2014-01-22.pdf
  • 2014-02-!9.pdf
  • 2014-03-20.pdf
  • 2014-04-22.pdf
  • 2014-05-21.pdf
  • 2014-06-18.pdf
  • 2014-07-20.pdf
  • 2014-08-19.pdf
  • 2014-09-22.pdf
  • 2014-10-22.pdf
  • 2014-11-21.pdf
  • 2014-12-22.pdf
  • 2015-01-18.pdf
  • 2015-02-20.pdf
  • 2015-03-21.pdf
I have a Hazel rule that puts the statements in whenever I download them. I would like to write another rule that zips up a year's worth of statements whenever there is one.

My first thought was to check that there were 12 matches, but I couldn't find a way to make Sub-file/folder Count only act on matches to previous conditions.

My second thought was to check when the December statement was added, but I couldn't find a way to just check the month of the matched date. Statement date occurs at 00:00 any day in Dec didn't work because Statement date just takes year, month, and day from the file name and the time is the current time when the rule runs.

I previously tried dropping into a script to check for the number of matches, but had a lot of difficulty working with the parameters that Hazel passes. Still, this might be the best option.

I'm pretty sure I could get it to work if I moved the files into a sub-folder, checked the count of its contents, and went from there, but I don't want to move 11 months of files, find that there aren't 12, and have to back it out.

Does anyone have suggestions? Is there something I've missed with the options I've tried?

Cheers,
Graham
gwagener
 
Posts: 5
Joined: Wed Jun 03, 2015 12:02 am

Re: Archive a year of monthly statements Wed Jun 03, 2015 12:21 pm • by Mr_Noodle
Not sure what you mean by "make Sub-file/folder Count only act on matches to previous conditions" but I think using the file count should work. For testing in December, you can use "occurs after 00:00" which would mean the whole day so it will match regardless of the time.
Mr_Noodle
Site Admin
 
Posts: 11868
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Archive a year of monthly statements Thu Jun 04, 2015 7:29 am • by gwagener
Of course I didn't even look at Occurs after because I was thinking it would be "occurs after December", not "occurs after X time on any day in December".

What I meant by only acting on the matches is have a rule that first has a condition checking for files that match a name pattern or something and then a condition that checks the count of the files that match the name pattern. However, since each rule is only operating on a single file at a time I don't think that could ever work. I've found a solution without it so it doesn't matter.

I figured out how to do things with three consecutive rules, then consolidated it into two. My first strategy was to have a condition that the name matches a date in order to set the date in a variable, then check the date is in December with Occurs after and create a folder with the same year. The next rule moved all the statements with the same year into that folder. The final rule archived the folder when it had twelve items in it.

I was able to consolidate it by using deeply nested conditions and basically nesting my previous first rule at the beginning of the second rule. Unfortunately, I couldn't use Occurs after in the nested conditions. I'm not sure if it's a bug, but "If [all] of the following conditions are met for [any of its subfiles or subfolders]" doesn't seem to work in the same way as the top level "If [all] of the following conditions are met". If I had a condition to set the date variable then a condition to check the date was in December it always set the variable to the first date it found then failed the whole rule because that date was in January. Since I only needed the year I just used one condition to check that the name matches [year]-12-[Anything].

These are the two working rules:
Image
Image

Here's the rule that doesn't work:
Image

Thanks for the help. Discovering the nested conditions really opened up the possibilities! If anyone can find any optimizations to these I'd be interested to see.
gwagener
 
Posts: 5
Joined: Wed Jun 03, 2015 12:02 am

Re: Archive a year of monthly statements Thu Jun 04, 2015 11:17 am • by Mr_Noodle
"occurs after" should work in nested conditions. Testing it here, I can get it to appear. How is it not working for you?

The top level "all of the following conditions" are intended to apply to the file/folder currently being matched. "any of its subfiles..." applies only to folders and applies the conditions to the subfiles within it, while still having the rule match the folder.

The way you have it now, you are matching a file with a certain pattern if it also has a sibling file which matches the pattern with the 12 in it. As for re-using the date attribute, the behavior you described is correct. The first one to match, that value carries over. If you don't want that, you should be using different date attributes or re-order the conditions so that the correct value is captured.
Mr_Noodle
Site Admin
 
Posts: 11868
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support