Over on the Hazel forum someone was trying to rename PDFs based on the original creation date of the PDF as found in the PDF metadata which is not necessarily the same date that Spotlight or Finder will show.
Although the OP was making the case that Hazel should include this by default, it does not (as far as I am aware, at least), so I did what I do, and wrote a script.
I called it pdf-rename-by-cdate.sh because I am very clever.
Note that the script requires the tool
poppler which you can install via
brew install poppler. I was going to try to parse the info myself, but realized very quickly there are multiple formats used in a handful of PDFs that I tested, and
pdfinfo worked with them all, so rather than reinvent the tool, I’m just building around one.
Anyway, it occurred to me that some folks here might be able to use this too.
The script attempts to be smart:
If you give it “filename.pdf” it will rename it to “filename (YYYY-MM-DD).pdf”
If the original filename already has “YYYY-MM-DD” in it, then the script won’t rename it.
If “filename (YYYY-MM-DD).pdf” already exists, it will try “filename (YYYY-MM-DD) 1.pdf” or “filename (YYYY-MM-DD) 2.pdf” etc until it does not find a conflicting file. I think this is basically what Finder does.
If you ask it to work on a file that is not a PDF, it will say “Hey, this isn’t a PDF” and skip it.
pdfinfois unable to find a Creation Date, it will report an error but not rename the file.
pdfinfois not found, it won’t continue, but will tell you how to install it.
To rename all the PDFs in a given folder, you can do:
It should also work with Hazel or Keyboard Maestro.