Pragmatism in the real world

Renaming files with Hazel

I’m a member of a number of groups that publish a magazine, either paper-based or PDF. I prefer the PDF version, so download from the website and then move to the relevant directory.

Recently, I realised that I could use Hazel to do this for me.

To take one example, the filename of the PDF that I download is of the format PE-{issue number}-web{some random characters}.pdf, for example: PE-123-web9j45s3gd.pdf. There’s sometimes a hyphen after web, but not always.

I want the filename to PE Magazine {issue number}

The rule in Hazel looks like this:


Screenshot of Hazel rename rule

Matching the name

Breaking it down, we detect that this is a file of interest with a Name matches rule. We can start with the literal string PE- as that’s constant, but then we need to match the number and also give it a name so that we can refer to it later.

This is done using the “Custom Text” element. You can then click on it to edit its attributes where I set its name to “issue” and the pattern to “Number” which matches sequential digits.


Screenshot of Hazel match attributes screen

The rest of the name match is a hyphen followed by an “Anything” element as we don’t care about any other characters.

Renaming

Now that we have we can use the Rename with pattern action with the literal “PE Magazine - ” followed by our “issue” custom element that we created in the match rule, followed by the extension.

Finishing it off

Once the file has been renamed, there’s a “Move to folder” action to move it the right place and then the folder is opened, so that I can grab the file if I need to.

That’s it. Automating the rename and move means that I don’t have to think about it again.

Thoughts? Leave a reply

Your email address will not be published. Required fields are marked *