Page 1 of 1

Hazel pattern for matching pairs of files (e.g. MP3 + PDF)?

PostPosted: Thu Jun 06, 2024 8:34 pm
by felciano
I have a Dropbox folder that MP3 recordings get dropped into and get processed automatically to transcribe them by an online transcription provider (Otter). Once the transcription is done, a PDF of the transcript is dropped into the same folder. For example, myfile.mp3 will eventually result in myfile.pdf showing up.

I'd like both of these files to get moved to a different folder once that processing has completed.

Is there a way to write a Hazel rule(s) that will only trigger once a pair of files show up with the same base name but two different suffixes (e.g. myfile.mp3 and myfile.pdf)?

Re: Hazel pattern for matching pairs of files (e.g. MP3 + PD

PostPosted: Fri Jun 07, 2024 8:41 am
by Mr_Noodle
Look up nested conditions in the manual. Using those, you can do something like:
Code: Select all
If (all) are met
    Extension is mp3
    If (all) are met for (any file in the same folder)
        Name matches (name)
        Extensions is pdf


This will match the file if it's a pdf if it has another file with the same name, but an mp3.

The problem here is that once you move the pdf, the mp3 will no longer have the pdf to match against. It might be best to move the mp3 first (reverse the conditions above so that it's matching the mp3 if there's a corresponding pdf), then move any pdf file you find later.

Re: Hazel pattern for matching pairs of files (e.g. MP3 + PD

PostPosted: Fri Jun 07, 2024 12:13 pm
by felciano
Mr_Noodle wrote:It might be best to move the mp3 first (reverse the conditions above so that it's matching the mp3 if there's a corresponding pdf), then move any pdf file you find later.


Thanks this was the hint I needed. In case anyone else runs into this, here's the full config that worked:

Rule 1: Move MP3 that has matching PDF
Code: Select all
If (all) are met
    Extension is mp3
    Name matches (name)
    If (all) are met for (any file in the same folder)
        Name matches (name)
        Extensions is pdf
Then
    Move to <folder>


Rule 2: Move PDF with no other same-named file
Code: Select all
If (all) are met
    Extension is pdf
    Name matches (name)
    If (none) of the following conditions are met for (the current file or folder)
        If (all) are met for (any file in the same folder)
            Name matches (name)
            Extensions is mp3
Then
    Move to <folder>