How to use extracted date attributes in Hazel scripts

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

Moderator: Mr_Noodle

Most of my PDFs (like bank statements or invoices) only contain a statement date. To file them correctly, I need Hazel to calculate the financial year (April–March in India). For example:

• 30-Mar-2025 → FY 2024–2025
• 14-Apr-2025 → FY 2025–2026

I can already extract the invoice/statement date from the file using Hazel’s “Contents” match and save it as a custom attribute (e.g. invoiceDate). The problem is: when Hazel runs a script or Shell Script, it only passes $1 (the file path). I don’t see any way to pass invoiceDate (or any other attribute) into the script.

Basically, I want Hazel to pick up the invoice date, figure out the financial year, and then move the file into the correct folder automatically. I can handle the script logic for FY calculation, but I’m stuck on how to get Hazel’s extracted attribute into that script. Is there any alternative solution?
grgsiocl
 
Posts: 5
Joined: Sun Aug 20, 2017 2:17 am

Instead of a script, how about using the date adjustment function. You can subtract 3 months from the date and then use the resulting year.
Mr_Noodle
Site Admin
 
Posts: 12000
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle wrote:Instead of a script, how about using the date adjustment function. You can subtract 3 months from the date and then use the resulting year.


Thanks, noodle, for the idea. Based on your suggestion, I did the following: I sorted the files into subfolders with a pattern: "Date (Subtracted by 3 months) - Date (Adjusted with 1 year and subtracted by 3 months)." I tested it on a file, and it worked fine. I just want to know if I understood your logic correctly or if there are any adjustments that need to be made.
grgsiocl
 
Posts: 5
Joined: Sun Aug 20, 2017 2:17 am

No, that should be it.
Mr_Noodle
Site Admin
 
Posts: 12000
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support