Either|Or with Tokens?

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

Moderator: Mr_Noodle

Either|Or with Tokens? Sun Jan 31, 2021 10:49 am • by steinar
I have Hazel rules to sort and rename all my PDF invoices and receipts based on file name and contents of the PDFs.

Problem:
I have some fields in the PDF that I want to use when renaming the files, that in certain cases can take more than one form. I normally use a "contains match" and set that to a token, that I reuse when renaming. In this situation I can't use a nested rule, because it would lead to two different tokens, and I can't use logic to decide which one to use for renaming. Do I have to create two (or more) almost identical rules to match these different cases?

Example:
I have a bunch of receipts/invoices from Adobe. The invoice numbers follow 2 different patterns:
- A: xxxxxxxxx (only digits)
- B: IENxxxxxxx

I want to grab the invoice number of either form from the content of the PDF to be part of the final filename. Can I somehow make one rule to fit both of these?

PS.
This would be a good use case for allowing regex in tokens
steinar
 
Posts: 2
Joined: Sun Jan 31, 2021 10:30 am

Re: Either|Or with Tokens? Mon Feb 01, 2021 11:35 am • by Mr_Noodle
If you want to use regex, then use a shellscript action, where you can use a regex in whatever language you are comfortable with.

You can use the same custom attribute with nested conditions. Each instance can have its own pattern. As long as you use "any", it should work fine as it will only need to match one of the patterns.
Mr_Noodle
Site Admin
 
Posts: 11868
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Either|Or with Tokens? Mon Feb 01, 2021 3:33 pm • by steinar
Shortly after posting this I realized that I can of course set up a token to accept 3x letter|digit + x amount of digits. That actually solves my problem without regex, and I can set up other conditions to make sure I don’t get false matches. I just instinctively look for more discriminatory conditions to avoid false positives...
steinar
 
Posts: 2
Joined: Sun Jan 31, 2021 10:30 am


Return to Support