Renaming file by pulling dates from orig file name

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

Moderator: Mr_Noodle

When I download PDFs of a magazine subscription, the filename is either in the format "January_5,_2026.pdf" or "Monday_4th_May_2026.pdf" I would like to rename the PDFs to the format 2026-01-05 Name of Magazine.pdf" and "2026-05-04 Name of Magazine.pdf" respectively.

I have spent a long time trying to configure a Hazel Rule myself and even a couple of hours using Claude and I can't get past getting a condition to match in preview using "Name" & "matches." I have no real coding experience but have used Hazel for years with lots of success renaming PDFs by pulling data from their contents. My guess that pulling date information that is right in the filename would be easy for me has been proven wrong for my skills.

I am running Hazel 6.1.2 on a MacBook Air M4 running Tahoe 26.4.1
trsands
 
Posts: 2
Joined: Mon May 30, 2016 4:47 pm

Look up "match patterns" in the manual. If you already know how to use those for contents, it is similar when using name. Uses "matches" instead of "contains match". The main difference is that when you use "matches", your pattern has to account for all the characters in the name, not just the part you are interested in.
Mr_Noodle
Site Admin
 
Posts: 12207
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle, thank you for this. You made me realize that I was trying to be too fancy by attempting to create a single rule to cover several differently named files. Sadly, this magazine PDFs are named in all different names even though they all included some form of date (Monday_4th_May_2026.pdf, Monday_11th_May_2026.pdf, Monday_23rd_March_2026.pdf, and even December_1,_2025).

I ended up dealing with this by creating six different rules to cover the single & double digit 'th's, the 'rd's, the 'st's, and the straight month_date_year patterns. It didn't take much time at all by using the duplicate function and a simple edit.

The incredible part of this program is that once you set up a rule, everything is so easy going forward.
trsands
 
Posts: 2
Joined: Mon May 30, 2016 4:47 pm


Return to Support