I am happy to post my code, but the main reason I am replying to your post is to mention that if you don’t want to install pdfinfo, you can also use spotlight to get the creation dates. However, I want the filename to be yyyy-ddmm_this_is_the_file_name.ext, and this script will detect a filename in the former format and convert it to the latter. However, the most useful role for this script is that typical when I create a new file, especially in naming a file as part of my scanning processing, it’s fastest for me to use a name in the format “this is the file name ” where yyyy.ddmm is obviously the date I want assigned to the file. All of these options were created for various workflows where I wanted to use this script. It supports a few command line flags to specific date or date and time to use in creating the new filename, to use the file’s creation date instead, to also lowercase the entire filename, and a flag to indicate that if the file in question actually does not exist (or is not a regular file) then generate an error rather than producing a new filename. I use it from other scripts, Keyboard Maestro, and Hazel to generate replacement filenames, with the script/KM Macro / Hazel rule that calls it deciding when/how to use the script and the changes filenames. It is written in python, and functions a bit differently than yours, in that it accepts a single filename on stdin, reformats it, and writes the resultant new filename to stdout. I also have a script that I used for file renaming. It should also work with Hazel or Keyboard for this interesting posting! To rename all the PDFs in a given folder, you can do: pdf-rename-by-cdate.sh *.pdf If pdfinfo is not found, it won’t continue, but will tell you how to install it. If pdfinfo is unable to find a Creation Date, it will report an error but not rename the file. 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. I think this is basically what Finder does. 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. If the original filename already has “YYYY-MM-DD” in it, then the script won’t rename it. If you give it “filename.pdf” it will rename it to “filename (YYYY-MM-DD).pdf” 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.Īnyway, it occurred to me that some folks here might be able to use this too. Note that the script requires the tool pdfinfo from poppler which you can install via brew install poppler. I called it pdf-rename-by-cdate.sh because I am very clever. 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.Īlthough 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.
0 Comments
Leave a Reply. |