Renaming historical docs based on contents

As I move to the paperless world, I am going thru a backlog of PDFs which I'm downloading from various places. My biggest question is renaming the file based on the date content within the OCRed PDF.
I would love to use the syntax:
year-month - nameofcompany.pdf
An example is from E-ZPass.
I download a PDF from them called, 'statementView.do.pdf' which goes into Downloads (all their statements have this name)
My current HAZEL rule says:
1. Kind is PDF
2. Name is statementView.do.pdf
3. Contact contains "Account Number: XXXXXXXX"
These work fine, but it doesn't address how to rename the files.
Ideally one of two things would happen.
1. Look at the content of the file for the Statement date (OCR TXT is Statement Date: 06/03/12)
2. Since the statement date is different from the activity, I would want to subtract 1 from the month (06/03/12 becomes 05/03/12)
3. For the renaming of the file I would just use the year/month. 12 become 2012 and 05 appended
4. new file name would be 2012-05 - ezpass bill.pdf
I see issues with the math for subtract months (i.e. on a January statement) so I could use the 'Activity For:' text (OCR TXT is Activity For: 05/01/12-05/31/12)
1. I would just want the first part of the dates (i.e. 05/01/12)
2. For the renaming of the file I would just use the year/month. 12 become 2012 and 05 appended
3. new file name would be 2012-05 - ezpass bill.pdf
Any help for a Hazel newbie. In a UNIX environment I would do a
Which would pass back 05/12 but I do see that Hazel does anything with variable which could be passed to the renaming function.
I would love to use the syntax:
year-month - nameofcompany.pdf
An example is from E-ZPass.
I download a PDF from them called, 'statementView.do.pdf' which goes into Downloads (all their statements have this name)
My current HAZEL rule says:
1. Kind is PDF
2. Name is statementView.do.pdf
3. Contact contains "Account Number: XXXXXXXX"
These work fine, but it doesn't address how to rename the files.
Ideally one of two things would happen.
1. Look at the content of the file for the Statement date (OCR TXT is Statement Date: 06/03/12)
2. Since the statement date is different from the activity, I would want to subtract 1 from the month (06/03/12 becomes 05/03/12)
3. For the renaming of the file I would just use the year/month. 12 become 2012 and 05 appended
4. new file name would be 2012-05 - ezpass bill.pdf
I see issues with the math for subtract months (i.e. on a January statement) so I could use the 'Activity For:' text (OCR TXT is Activity For: 05/01/12-05/31/12)
1. I would just want the first part of the dates (i.e. 05/01/12)
2. For the renaming of the file I would just use the year/month. 12 become 2012 and 05 appended
3. new file name would be 2012-05 - ezpass bill.pdf
Any help for a Hazel newbie. In a UNIX environment I would do a
- Code: Select all
grep "Activity For:" <filename> | awk '{print$3}' | sed -e s^\/.*\/^/^
Which would pass back 05/12 but I do see that Hazel does anything with variable which could be passed to the renaming function.