I am new to Hazel and am trying to figure out how to get it to rename files based on a rather complex pattern. I have a folder where there are files in the format
Title - SubTitle – FirstName1 LastName1; FirstName2 LastName2 – other characters that I am not interested in.pdf
I would like the renamed file to look like
LastName1 LastName2 Title.pdf (or whatever the file extension was originally)
I thought regex could possibly help me but am not sure how to put that into a Hazel rule. I am also a noob when it comes to Apple/Shell scripting and so am hoping there is a solution without that.
I also tried playing around with the Hazel to read the contents of the file but I am not sure how to make it pick up the title and last name of author(s) from that.
I’m sure you’ll get sound advice here, but suggest you also post your requirements on the Noodlesoft forum. Paul Kim (dev) is very active and helpful there. Get the word directly from the maker.
I’d concur with @KVZ, but in addition, why trouble a human when you could pop this into your LLM of choice? I’ve found ChatGPT to be knowledgable on Hazel rule construction. LLMs are ideal for these kind of things. May take a little bit of back and fore, but it usually comes up with the goods.
I recently built something similar for renaming and sorting screenshotted coupons like extracting vendor name and expiration date from screenshot and rename file as „vendor - expiration date - org-title,png“.
Hazel is extremely powerful and one of the best actions in my experience is „match“ which would allow you to dissect the file name into the parts you want (described above) and piece them together again as desired.
Does your firstname lastname always only contain a single word? No double names? Spaces? Only as simple as „John“ „Doe“ ?
Assuming the pattern of your starting filename is quite strict, this could be a starting point.
With the “matches” action, you can use Tokens to pattern your filename and reuse those tokens for the renaming (sorry if the wording might not be quite correct):
Yeah, he’s eerie fast over there. It’s a helpful, but be sure to follow the posting rules. They’re pretty strict, but that’s what keeps the forum clean and helpful.
I’ve always been a good web searcher, happy to put in the hard yards to research solutions. But the advent of LLMs has made this infinitely more productive. In my experience they also open up/make you think about other ways of skinning the same cat, or, just expand things further to a level I would have not thought of myself. Best of all, the response is immediate, iterative and momentum-building.
I know that “vibe-coding,” on here is a pejorative term. And to be honest, I’m not interested in building the 124th clone of an already existing app.
But for me, for sounding out AppleScripts, Hazel rules or, say, JavaScript to run in Drafts’ actions, they are great tutors. Are the solutions they provide the most elegant or efficient? I really don’t know. But as I’m just creating small, quality of life enhancements that work for me and not the operating system for an F35 fighter, I really don’t care.
So, personally, I would always run my query by an LLM first, and only hit a forum with it – thereby taking up a human’s time – if my efforts had already drawn a complete blank.
Just a little warning because I almost went crazy about this matter:
It is very easy to get conflicts with rules if you don’t specify your rules enough. It is also easy to get errors you will just see in the logs. The last two months Hazel was using much more battery than usual. I found out that one of the rules tried to read text in pictures. This lead to errors loops. So it is good to always open the log from time to time and see if there are errors.
ChatGPT drove me crazy when trying to get it to build Hazel rules. I uploaded the full manual and told it to read and still it was inventing stuff. Finally I had to tell it the page numbers before it gave me the right answer but by then, I had read enough of the manual that I could do it myself.