Hazel - renaming using contents of file


#1

Hi,would anyone be able to tell me if there is a way to rename a document using an invoice number that is within the document. I can figure out how to do it using the date but I can’t seem to work this out. Thank you


#2

Provided the invoice number follows a consistent pattern (same number of digits each time) and is sufficiently unique (there isn’t any other number with the same number of digits in the invoice) you should be able to do it using the “contain match” condition.


#3

Thank you for your help but it hasn’t worked unfortunately, I have tried evrything. The invoice number is still searchable using spotlight so not all is lost. Thank you again for your help :smiley:


#4

Is it the same invoice number each time? If so you could use a “contain” instead of a “contain match” like @ChrisUpchurch recommended. I guess any additional information would be helpful so we can better recommend a solution :wink:


#5

Hi, I have provided more information in this post. The invoice number is always different except it always ends in /01 eg. 499970/01 The invoices come in as .txt so I have to convert them each time into pdfs. Unfortunately the words invoice number do not come before the invoice number itself whatever way it has been converted. So I can’t use invoice number in the contains match variable.


#6

I’m not at My Mac right now to test this but have you tried something like this for your match criteria?

111111/01

Where the first six 1s are the digit placeholder and the /01 at the end of it is standard text?

But also since they come in as TXT, you could save those, have Hazel trigger a shell script to extract the reference (command line utilities are awesome for processing text files!), rename the file and then convert it to PDF.

I do have to ask out of curiosity though. Why are you converting the TXT to PDF? For annotations of including in a combined PDF or something?


#7

Hazel matches and renames the file for me using the Custom Text token.

Hazel%20Screenshot%202018-07-14


#8

Brilliant thank you very much that worked I was really stuck but didn’t realise you could do that with the custom text. I am converting them into PDF so they are searchable on iOS. They are delivery invoices for a business and they are 5-10 pages long and sometimes we need to find products that are on the invoices and this saves times. Thank you again :grinning:


#9

Thank you for the screenshot it really helped to figure out the custom text input. I’m still learning how to use hazel so this has really helped.


#10

It took me a second to get this. Many thanks!