Tip: Create an empty folder structure with Automator

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

Here's a handy method using Automator and Hazel to automatically create a specific folder structure of empty folders within a folder. I use this for client projects, since they are always the same.

The Hazel rule would be something like:
Image

The rule
Code: Select all
[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:
Image
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.

EDIT 2018-01-01: updated screenshots with more detailed annotations, edited post description for more clarity
Last edited by gcoghill on Mon Dec 02, 2019 3:07 pm, edited 2 times in total.
gcoghill
 
Posts: 290
Joined: Tue Sep 18, 2007 8:09 am
Location: Kent, OH

Does this create a _ref folder under the current folder? Is there a reason why that part is done in Automator?
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Yes, it creates a folder named "_ref" within the current folder. Is this something I can do within Hazel alone? I recall there being a snag when I built it, but perhaps that was with an older version and something has changed to make this possible.

I typically add 4 new folders for each new client folder. If I can drop Automator from this workflow I'd be glad to, please let me know what you're thinking!
gcoghill
 
Posts: 290
Joined: Tue Sep 18, 2007 8:09 am
Location: Kent, OH

I just checked the rule, and I do not see any way to create new folders via Hazel alone.
gcoghill
 
Posts: 290
Joined: Tue Sep 18, 2007 8:09 am
Location: Kent, OH

Sorry, I was thinking of Sort into subfolder creating new folders but it requires you to put something in it. In this case, you are just creating a new empty folder so nevermind.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

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.

If anyone could help me figure this out I'd be very happy.
Janov
 
Posts: 1
Joined: Tue Dec 11, 2012 2:36 am

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.
gcoghill
 
Posts: 290
Joined: Tue Sep 18, 2007 8:09 am
Location: Kent, OH

This is a really great time saver. Thanks for posting this great tip.

If i may ask, how in Automater can you then create further sub folders within sub folders.

So i have my new watch folder and automator creates 5 sub folders. I would like sub folder 1 to have a further 2 sub folders, subfolder 2 to have 2 and so on.

Thanks again
Chuggett
 
Posts: 30
Joined: Wed Mar 16, 2011 9:17 pm

I figured it. Its all to do with creating additional variables and the order in which you create it. The thing to watch out for is that "Ignore this actions input". Not selecting that sends automator into a perpetual folder making machine.
Chuggett
 
Posts: 30
Joined: Wed Mar 16, 2011 9:17 pm

Chuggett wrote:This is a really great time saver. Thanks for posting this great tip.

If i may ask, how in Automater can you then create further sub folders within sub folders.

So i have my new watch folder and automator creates 5 sub folders. I would like sub folder 1 to have a further 2 sub folders, subfolder 2 to have 2 and so on.

Thanks again


Glad you found it useful and thanks for the thanks :) this one a big time saver for me. Or at least and annoyance-saver.

Glad you figured out your later issue.
gcoghill
 
Posts: 290
Joined: Tue Sep 18, 2007 8:09 am
Location: Kent, OH

I know this is a really old topic but it's exactly what I want to do...
I have no experience with automator and I'm beginner with hazel.

My hazel script seems to be ok (hard to mess with it :P) but I don't get the automator part.
I followed what you said but Current Folder isn't working.

Could somebody actually detail how to create this variable because mine got only the name and I didn't find any way to configure it or so :/
NoSpHieL
 
Posts: 3
Joined: Fri Apr 21, 2017 7:54 pm

NoSpHieL wrote:I know this is a really old topic but it's exactly what I want to do...
I have no experience with automator and I'm beginner with hazel.

My hazel script seems to be ok (hard to mess with it :P) but I don't get the automator part.
I followed what you said but Current Folder isn't working.

Could somebody actually detail how to create this variable because mine got only the name and I didn't find any way to configure it or so :/


Hello. Did you get any responses to this? I want to do the same thing -create subfolders when I create a new folder in a particular folder. Would you mind sharing what you came up with. I am new to actually trying to use Hazel despite having had it on my computer for a couple of years. I am overwhelmed and would really like to not recreate the wheel.
Antoinetteb
 
Posts: 2
Joined: Wed Dec 27, 2017 8:56 pm

Looking over my screenshots, they are a bit misleading. If you are having issues with this Hazel action, then I'd suggest removing the last three rule conditions in my example:

Code: Select all
(Name)(does not start with)[_]
(Date Created)(is in the last)[5](minutes)
(Color Label)(is){Green}

Those are particular to my setup, and in particular the "Color Label" condition could cause this action to fail. This is included because I have another Hazel rule set up for this same folder that runs prior to the "folder creation" rule here.

That prior rule sets the color label of the folder intended to get the subfolders to Green so that other folders do not get the subfolders added to them.

I do this because I have this Hazel rule running on my "Current Projects" folder. I only want Hazel to add the new folders once. So what I do is have multiple rules that act on this "Current Projects" folder.

This first one detects new empty folders added to "Current Projects". When it detects one, it sets the color label to Green. This is used to trigger the "Create Subfolders" rule we are working with here. This rule detects folder with a color label of Green, and then runs the Automator action to create subfolders within this Green-labelled folder.

But if you don't have the other rule labelling your folders Green, then this rule will fail if you have the exact conditions I show in my screenshot.

The only rule conditions that you must have in the rule are the first three. And technically, only the first two. The "untitled" rule just gives you (or other Hazel rules) some time to work on newly-created folders, which get the default name of "untitled".

---

Also, make sure you are looking at the screenshots in detail; often I find that these Hazel or Automator rules fail because I overlooked some small setting. Make sure the Automator action is set to

Code: Select all
receive selected [folders] in [Finder]

up at the top. That's an easy one to overlook.
gcoghill
 
Posts: 290
Joined: Tue Sep 18, 2007 8:09 am
Location: Kent, OH

gcoghill wrote:I just checked the rule, and I do not see any way to create new folders via Hazel alone.


I know this is a really ancient thread, but I just wanted to clarify that it IS possible to create folders and sub-folders with Hazel alone. The way to do it is by using Tokens to name a directory using the "Sort into sub-folder" function. (A "token" is a piece of text, a word, a number, a date, or a series of character in the text of your PDF).

Image

Supposing your pdf contained the text "Name of client: Jones" and "Type of Vehicle: Car", then the above will create two new sub directories called Jones/Car. Then the file will be moved to deepest directory just created (Car).
Trickyt57
 
Posts: 55
Joined: Tue Sep 18, 2018 12:17 am

I think the point here is that sometimes people want to create the folders without having a file to put into them. They want to create all of them up front for future use.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Next

Return to Tips & Tricks - DO NOT POST QUESTIONS