-
-
Notifications
You must be signed in to change notification settings - Fork 169
Renaming PDF based on specific date found #449
-
Hi everyone!
Organize and regex noob here ...
Trying to find a replacement for the MacOS app Hazel and one of the really cool features is to specify in the content match which date to capture as a variable in order to do date-math. Best example is a Credit Card billing statement which has things like ...
Billing Period: 03/12/24-04/09/24
In the above case I would tell Hazel to match the 2nd date (04/09/24) and then rename the file to 'some_credit_card_202404.pdf' and move it somewhere. Manipulating the detected 2nd date from MM/DD/YY to be YYYYMM.
I think it can kind of be done with - filecontent: '^Billing Period: \d{2}\/\d{2}\/\d{2}-(?P<statement_date>.*)' to capture 04/09/24 as statement_date but when I run organize sim on the PDF in question it reports "Nothing to do"
It's possible my action is messed up and it can't figure out what to do. I was simply trying to find the file(s) first and then simply show I captured the variable.
I am running organize via a scoop.sh installation of Python (3.13) and have poppler installed via scoop.sh as well. I can confirm that I can run pdf2totext on the PDF in question from a shell and I get a txt version of the PDF in question.
The config
- name: "Test Rule"
locations: "D:\\Folder 1\\Folder 2\\Folder 3\\Files"
subfolders: true
filters:
- extension: pdf
- filecontent: '^Billing Period: \d{2}\/\d{2}\/\d{2}-(?P<statement_date>.*)'
actions:
- echo: 'Found a {extension.upper()} with a credit card statement date of "{statement_date}": "{name}"'
I also did a basic check of the regex on the string in question (regex101.com) and it behaved as-expected.
What have I done wrong?
Thanks in advance!
Scott
Bonus points if you can give me a hint as to how to how to manipulate the statement date from MM/DD/YY to YYYYMM but I suspect I'll need to use the python action to handle that part. Baby steps 1st. :-)
Beta Was this translation helpful? Give feedback.