Naming and filing receipts by date

Talk, speculate, discuss, pontificate. As long as it pertains to Hazel.

Moderators: Mr_Noodle, Moderators

Naming and filing receipts by date Wed Feb 05, 2014 8:53 am • by alkan
Hello,

I love Hazel's ability to search files for patterns such as dates. I'm trying to create a rule or rules to scan a folder of receipts, look for the date and prepend it to the filename, then sort it into subfolder for the corresponding year.

For example, if it finds "1/24/1984" in the file, Hazel should prepend the filename with "1984-01-24", then move it to the subfolder "1984".

Currently, it seems 1 Hazel rule is required for each possible date pattern, e.g., "d.m.yy", "d.m.yyyy", "dd.mm.yy", "dd.mm.yyyy", "m/d/yy", "mm/dd/yyyy", "Month dd, yyyy", etc., in order for renaming (prepending the date) to work.

Also, for some reason my additional rule to move files whose name starts with "2014" to a folder named "2014" is not being triggered. The rule is simply:

If all of the following conditions are met
Kind is not Folder
Name starts with 2014
Do the following to the matched file or folder:
Move to folder 2014


Is there a way to pack all these rules into one or two Hazel rules, perhaps with a script?

I'd be very grateful for any help. This would be the Holy Grail of electronic receipt filing!


Kind regards,

Albert
alkan
 
Posts: 3
Joined: Wed Feb 05, 2014 8:44 am

Re: Naming and filing receipts by date Wed Feb 05, 2014 10:15 am • by alkan
I figured out a solution based on learning Hazel's behavior: It seems Hazel only matches one rule per file per folder, so this makes it necessary to combine rules into one wherever possible. Also, the order of your rules matters.

My new rules have this format:

If all of the following conditions are met
Contents contain match "d.m.yyyy"
Do the following to the matched file or folder:
Rename with pattern: "d.m.yyyy" [the pattern is then edited to be "yyyy-mm-dd"] name extension
Sort into subfolder with pattern "d.m.yyyy" [this pattern is then edited simply to "yyyy"]


I created one rule for each possible date format ("d.m.yyyy", "mm/dd/yyyy", etc.).

IMPORTANT: Rules matching "yyyy" always belong before those matching only "yy"! Otherwise a file containing "Receipt 2/5/2015" will first match the pattern "m/d/yy" for "2/5/20" and incorrectly be filed into a folder for the year 2020.


Hope this helps,

Albert
alkan
 
Posts: 3
Joined: Wed Feb 05, 2014 8:44 am


Return to Open Discussion