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

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

Moderator: Mr_Noodle

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
ChrisJenkins
 
Posts: 8
Joined: Sun Jan 28, 2018 11:44 am

That can be easily done with the replace text option in the renaming section.
Image
"Behind all the inhuman aspects of automation (...) its real possibilities appear: the genesis of a technological world in which man can finally withdraw from (...) the apparatus of his labor – in order to experiment freely with it." /Marcuse
Robert
 
Posts: 52
Joined: Sun Dec 16, 2018 8:05 am


Return to Support