Hazel rule to remove leading space(s) from filename


When I read articles online I often wish to save it as a PDF for reference. In Safari on iOS I use the “reading mode” (the four lines in the address bar) and the “create pdf” share. I save the articles to a folder, and Safari names them by default to “SafariViewService” with a datetime.

In order to find the relevant articles again, I have made a Hazel rule to rename the file based on the content, a custom field set to “everything”. This takes the first line of the file (usually the headline) and uses this as the filename. That’s all well and fine.

Except that for some files there are leading spaces, which isn’t nice. And I can simply not find a way, within Hazel, to get rid of these. I can identify files with a leading space, but cannot find a way to rename it without the spaces. I see the character categories, but it seems that full regex is not implemented (that would make life easier…)

Any ideas?

Try this (I just tried it and it worked)

If name matches [<rest=anything]

Then rename to rest

Anything is the “…” pattern and rest is the name that I give to the pattern


Would you be able to upload a screenshot of this Hazel rule please.

I forgot to note that there is a at the beginning before the pattern,i.e. <.rest>

Hope that helps.

1 Like

oh… i didnt forget… it appears that this site removed my text … it did it again in my second post.
So there is a 1 character space in the match before the *rest.

Great! Thanks! I added the rule that removes leading spaces to my folder. I cannot avoid those in the initial renaming rule.