Automatically Create a Specific Folder Structure with Automator & Hazel

Here’s a method using Automator and Hazel to automatically create a specific folder structure within a folder. I use this for client projects, since they are always the same. With this setup, I just add a new folder to my “Clients” folder, and all the standard sub-folders I need added are auto-created by Hazel, via Automator. 

The Hazel rule would be something like:

Hazel create folders

The rule

[Name] [does not start with] "untitled"

is to prevent Hazel from running this rule on new folders which default to being named “untitled” when created. This rule is probably optional.

Here is the setup for the Automator Service:

automator create folders

You need to manually create a new variable (in this case “Current Folder” but can be named whatever you like). Make sure you use this same variable in the New Folder “Where:” menu. You can do this by dragging the variable token from the bottom of the window to the drop-down menu next to “Where:”.

Also be sure that all the areas outlined in red are the same as in the Automator screenshot:

  • Note the drop-down menu options at the top of the Automator window: Service receives selected [folders] in [Finder]. Make sure this matches.
  • Note how the Options tab in the New Folder step has the “Ignore the action’s input” checkbox checked (and that it is not checked in the “Set Value of Variable” step)
  • Note that there is only one variable token at the bottom, and it is used in both steps.

Repeat the “New Folder” action as many times as you need for other folders, changing the name of course. But keep the variable token the same.

I made it a Service so I can access it manually if need be. But mostly I invoke this via Hazel.

(Updated 2017-12-30 with new and annotated screenshots, as well as a more detailed description. Hoping to clear up issues people have been having with this setup, which still works fine for me on macOS 10.12.)

20 thoughts on “Automatically Create a Specific Folder Structure with Automator & Hazel

  1. I had a few minutes and was reading this and it is cool but thought the same thing could be accomplished in the finder quite easily. If you set up the structure you want some where on your drive you can just copy the root folder and paste it in where you want and the entire structure is replicated. For Example I set up a folder Templates and in there created a sub folder Testa and then in there testb and then in there testc. I then went to the testa folder and copied it. Went to the documents and pasted it, the entire structure is replicated. Ie now under documents there is Testa is there testb is in there and in it is testc. Is this not the same as what are doing or am I missing something. Cool way to learn more about hazel though.

    1. Indeed you could do this the way you mentioned. But that requires navigating to the folder where you stored the template, option-dragging to the new location, multiple Finder windows, etc. With my method, when I create a new project folder, it all happens automatically. If you haven’t noticed, I love automating stuff on the Mac :)

  2. I saw this one on the Hazel forums also, and have put the same question on the forums over there:

    It might be my ignorance, is this rule supposed to create the subfolders in the folder Hazel is watching, or within the folder created? I have tried to duplicate the rule and it keeps creating the subfolders in the folder Hazel is watching, not in the folder created.

    I’d appreciate any help/info you could provide.

    1. This rule watches for new folders in the watched folder, and then creates subfolders within any new folders meeting the criteria.

      Hazel watches “Watched Folder”; if I add “Subfolder 1” to the “Watched Folder”, Hazel will create the new folders within “Subfolder 1”. Hope that helps.

  3. Very useful, thank you!
    Now my big question is, I want to create several folders (manually) like Job_01 … etc with subfolders in them, lets say “Filetype_A” and “Filetype_B” thats perfectly done with your description.

    Now I will import files, I want to distribute between those two, seperated by filetype, but as every import has a different enclosing folder (job_02 job_03 etc) right now I am copying the rule to move the files in hazel, but then have to modify every rule manually to make the files to go to job_02 > Filetype_A
    if I forget to do that the files end up in the wrong job folder … anyway its not satisfying yet.

    Do you have any idea? This would make my workflow so much more effective

    Thanks

    1. just to be clear:
      right now I drop all files in eg Filetype_B in the right job folder, but then

      I have to modify every rule manually to make the files go to
      job_02 > Filetype_A,
      job_03 > Filetype_A
      job_04 > etc

    2. If I am understanding you properly , you should be able to do this by setting up the rule so it matches a folder name pattern, instead of matching the name exactly.

      The rule pattern might be:

      Name matches “Job_(number)”

      Where the info in parentheses is the match token in Hazel. This prevents false matches (it only matches folders that have names starting with “Job_” but allows for variations.

  4. Hi George, This looks very nice.. If I had a say 4-5 deep folder structure within one master folder, and I wanted to move all of the files whose names contained _adk_ for example to an already existing identical folder structure in a different location, could I adapt your script here to do that?

    1. This uses Automator, and not a script. But either way, it’s for creating blank folder structures and not copying files. I think you can just use Hazel’s built-in “Copy” functionality, which now includes options to retain existing folder structures. I’ve never used those options though so I am not exactly sure how they work. But it sounds like it’s exactly what you want.

      If not, try asking your question over at the Hazel forums, lots of helpful users there including the developer.

    1. Thank you, yeah since I posted this I’ve discovered simpler methods to do this. the Automator methods is nice for non-coders just getting into automation, but yeah shell scripts are the way to go. I’m not much of a coder so I rely on Frankensteining together code I find online.

  5. First, this is exactly what I was looking for !
    Thank you so much George ;)

    However, I seem to be the only one who didn’t manage to make it work :P
    (Don’t throw me rocks plz, I never used Automator :s)

    Anyway, I followed your steps, it looks easy but apparently my automator service doesn’t work and I guess it come from the “Current Folder”. It was strange when I created this variable because there is no options or nothing to configure, just a name to type… I would have type “bullshit” it would have been the same ? oO Or maybe I’m missing the way to create a variable… Or else, maybe it’s because I’m french and so english entry doesn’t work ? Or just racism…

    But if you have any idea, it would be amazing ;)
    Thanks

    1. Make sure your Automator action looks exactly like the screenshot, especially at the very top of the Automator screen: “Service receives [folders] in [Finder]” — that top conditions bar plays a factor and easily overlooked.

      Make sure you are using the same variable in both Automator steps. Do not create a new one for the “New Folder” step.

      And yes you can name the variable anything you’d like. But the one you create int he “Set variable” step has to be the same variable used in the “New Folder” step.

      Look at the bottom of the Automator window, below the steps. There is a Variables section. Make sure you have only one variable there. Drag it to the “Where” menu in the “New Folder” step to make sure you’re using the same one in both steps.

  6. Hey George,

    Thank you so much for writing this guide! I’m trying to replicate it to archive payment receipts every month into a new folder with the month’s name (eg. 2017-10), however I can’t get the Automator service to work. Is there a change in High Sierra?

    1. I am now on macOS 10.12 and this still works fine for me. Make sure your Automator action looks exactly like the screenshot, especially at the very top of the Automator screen: “Service receives [folders] in [Finder]” — that top conditions bar plays a factor and easily overlooked.

      Make sure you are using the same variable in both Automator steps. Do not create a new one for the “New Folder” step.

      Lastly, for what you want to do, if you are using Hazel then you do not need any of this Automator stuff at all. Just use Hazel’s “sort into subfolder” action to sort as needed, with the name structure you prefer. Hazel will auto-create folders as needed.

  7. I updated this post with new and annotated screenshots to hopefully address what I think are potential problem areas when configuring this setup. I also edited the text to describe things in more detail.

    This is one of my more popular posts and I’ve found many people have issues with getting it to work. I hope this solves those issues.

Leave a comment