Using Hazel to sort files based on the first four characters

Hey:

It could just be that my googling skills aren’t up to par today.

And I figured instead of spending hours trying to figure it out, I’d ask a fellow automating genius.

Does anyone have any idea how I can monitor my downloads folder using hazel, for a wave file that starts with:

DM36

For example, the third and fourth characters will change based on the episode recorded, and then move this wave file into a Google Drive folder titled:

DM36

Again, the last two characters will be respective of the episode number.

I have the folders in Google drive through episode 50, now all I need to do is figure out how to move my wave file from download into Google Drive respected folder automatically.

Thanks for any assistance with this.

Michael

Host of the your own Pay podcast network.

At a high level, I’d probably just approach it like this, but I’m sure there are many(!) ways to approach this.

The initial pattern match I think could be something like this where the digits and asterisk are tokens and the rest is text.

DM11*.wav

Ref. https://www.noodlesoft.com/manual/hazel/attributes-actions/attribute-reference/using-match-patterns-in-conditions/

The file extension could be moved out, or the operation could be handled by the script approach below.

I’d probably then use a Bash shell script where Hazel passes in the file path and the script then pulls out the filename, takes the first 4 characters, and then builds a new file path based on the original, which it then moves the file to.

1 Like

If you want to avoid scripts, it is possible to do this just with the Hazel interface too:

The ‘Episode’ is a Custom Text token as @sylumer suggests, which is then reused in the last rule:

For your purposes you would also probably want to add a file type to the conditions, and set the folder to the relevant Google Drive folder rather than Documents.

(Incidentally, this should create any necessary subfolders as required so you don’t have to do that manually. I’m sure the above solution would do that too.)

Hope that helps but if we can help with anything in more detail of course don’t hesitate to ask!

2 Likes

Can you kindly let me know what important information is included in the screenshots? Unfortunately, voiceover on iOS does not read screenshots to blind or visually impaired individuals. Thanks for your assistance in this.

And I appreciate you breaking it down as it seems you have done.

Oh, I’m sorry, I didn’t realise, how thoughtless of me! I’m just heading to bed but will write something out properly first thing tomorrow.

Not thoughtless at all, I greatly appreciate the fact that you’ll take the time to write out a more detailed exclamation tomorrow. Take your time

Thanks again.
Michael
@payown

No worries at all!

The first screenshot is of the Hazel rule as a whole.

The only condition I had was “Name matches DM[Episode][Anything]” where [Episode] and [Anything] were tokens. The Episode token I will go into in a bit more detail in a second and the Anything token is one of the standard options you get when you select the “match” option.

As I mentioned, you probably want to check the file type here too.

Then the ‘do the following’ section has the following instructions:

  1. Move to folder “Documents” (obviously select the right folder here rather than documents) and
  2. Sort into subfolder with pattern DM[Episode].

The [Episode] is the custom token from above and is one of the options that appears in the menu that shows when you are in the text field.

The second screenshot is of the [Episode] custom token. All it is is a custom token with the name “Episode” and made up of one number block. If you needed it to match just the two digits (for example if there were more than two digits in the file name after “DM” but the rest weren’t relevant) you could use two ‘digit’ blocks instead to match just the first two.

Hopefully that helps to explain somewhat, but again let me know if anything isn’t clear. Turns out that Hazel rules aren’t the easiest thing to explain clearly, haha!

1 Like

Just to help as well, if it does, here’s that same rule based on your description and images: https://www.dropbox.com/s/p4bybwiuz6sniun/sample.hazelrules?dl=0

Warning: Mine sorts into a folder called “FontAwesome PNGs” :wink:

1 Like