I would like to seek some help on a Hazel question. I know this might be better posted on the Hazel forums, which of course I can do, but since I frequent here and not there, I decided to through this out here first.
I have a generic inbox folder (creatively named _Inbox; the underscore for sort ordering) into which downloads, scans, and pretty much anything that needs later filing goes.
I have a rather large set of Hazel rules that detect many of the files that wind up their, use their contents to figure out what they are, rename and possible tag the files, and then ultimately move them to a target destination. For example, the contents of a downloaded electric bill allows Hazel to detect it, rename the file to the format <billing_date>_electric_bill.pdf and then move it to the Bills/Electric folder.
The moving part is what I am trying to modify for several reasons. First, what I like to do is have the file renamed and tagged, but then sit in the _Inbox for some time period before being moved in case I need to work with it shortly after the download, scan, etc. Therefore, since there is no Hazel action (that I am aware of) where you can place an intentional delay in the action rules processing, this requires a separate rule for each type of file, one that does the rename initially and a second one that has an added condition of “file added not in the last XX minutes” which then does the move.
Secondly, it does arise from time to time that I want to relocate the target folders of one or more type of file, and that means a lot of rule editing. This is even worse at times when I migrate to a new Mac, which I do more often than is reasonable.
So: my thought was that it would be ideal for me to have one rule that does all of the file moving. This rule would take the file name patterns (eg it would have the ability to recognize _electric_bill.pdf and _gas_bill.pdf) and would have a table that matched patterns to the target folder and then do the move to the target folder.
On the surface, the Hazel pattern matching capability that allows you to create a table would seem to be perfect for this purpose, with a pattern column providing the match pattern and a destination folder providing the place to move the file. I could easily maintain this data in an external file that could be easily editing with batch replacements and so forth.
My problem: as far as I have been able to determine, the table pattern matching in Hazel does not allow you to actually insert a pattern into the cells of the table, only fixed text, and therefore there is no way to do pattern matching of any sort - and since these files will pretty much always have the date in the file name which is obviously not going to be a fixed string, it does not look like I can accomplish this with the built in Hazel tables.
I was wondering if anyone knew something that I have not been able to find that could help here?
If not, it is not all that difficult for me to create a script that can do the same, but it’s a bit of a pain. To return the destination folder to Hazel (I would prefer Hazel do the file move rather than doing so in the script, although perhaps not for any good reason) the script needs to be in AppleScript as the only way for scripts to pass data back into Hazel tokens. However, doing regex or pattern matching in AppleScript is not what I would call convenient, so I will need to embed a script in another language (probably Python) to do the lookup in the file. Not the most difficult thing in the world, but the kludge level grows, and I would hate to miss a solution internal to Hazel that I am not aware of.
(BTW: I know that the AppleScript could use a shell command to grep the file that associates patterns to target folders, but that is backwards of how grep works, because the lines in the file contain the regex patterns which I am matching against the string of the filename, which is backwards. I am sure this could be down with something like awk, but it willl take 10 minutes to write the Python script, so I might was well.)