Page 1 of 1

How to ensure generated filenames don't contain 'bad' chars

PostPosted: Sat May 18, 2019 5:35 am
by ChrisJenkins
We use Hazel to process a huge assortment of e-mails (as PDF files). Many of these e-mails relate to purchases and so we have rules that extract information, such as the item description, from the e-mail and ultimately use this to rename the file to something sensible.

A big problem that we encounter is that often the item description may contain characters that you really don't want in filenames. '/' is a great example but there are others too such as '~', '!'. '*' and so on. Currently Hazel doesn't enforce any rules here so one often gets filenames with embedded '/' characters which results in an interesting situation to say the least (macOS really doesn't like such filenames).

I'm looking for a way to ensure that the filenames generated by Hazel when we use the 'Rename with pattern' option never contain any of these characters (either by removing them or replacing them with e.g. a space) but I can't find any way to do this. I had thought about using a shell script but Hazel doesn't allow you to pass any parameters to scripts! It automatically passes the (current) filename as the first parameter (which is great) but I would need to pass an additional parameter (the 'pattern' that I want to use for the renamed file [with the extracted values already substituted]) in order to achieve what I need.

This is really a big problem for us so I am hoping someone here may have some useful suggestions.

Also, maybe the shell script facility in Hazel could be enhanced in the future to allow additional parameters to be passed...

Thanks for any suggestions!

Chris

Re: How to ensure generated filenames don't contain 'bad' ch

PostPosted: Sat May 18, 2019 7:06 am
by Robert
That can be easily done with the replace text option in the renaming section.
Image