Page 1 of 2

Tip: Create an empty folder structure with Automator

PostPosted: Sat Mar 16, 2013 4:45 pm
by gcoghill
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

Re: Tip: Create a specific folder structure with Automator

PostPosted: Mon Mar 18, 2013 2:42 pm
by Mr_Noodle
Does this create a _ref folder under the current folder? Is there a reason why that part is done in Automator?

Re: Tip: Create a specific folder structure with Automator

PostPosted: Mon Mar 18, 2013 2:49 pm
by gcoghill
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!

Re: Tip: Create a specific folder structure with Automator

PostPosted: Mon Mar 18, 2013 3:05 pm
by gcoghill
I just checked the rule, and I do not see any way to create new folders via Hazel alone.

Re: Tip: Create a specific folder structure with Automator

PostPosted: Tue Mar 19, 2013 1:15 pm
by Mr_Noodle
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.

Re: Tip: Create a specific folder structure with Automator

PostPosted: Mon Jul 08, 2013 2:37 am
by Janov
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.

Re: Tip: Create a specific folder structure with Automator

PostPosted: Sat Jul 13, 2013 12:26 pm
by gcoghill
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.

Re: Tip: Create a specific folder structure with Automator

PostPosted: Fri Aug 01, 2014 9:28 pm
by Chuggett
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

Re: Tip: Create a specific folder structure with Automator

PostPosted: Fri Aug 01, 2014 10:48 pm
by Chuggett
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.

Re: Tip: Create a specific folder structure with Automator

PostPosted: Sat Aug 02, 2014 12:10 am
by gcoghill
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.

Re: Tip: Create a specific folder structure with Automator

PostPosted: Fri Apr 21, 2017 7:59 pm
by NoSpHieL
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 :/

Re: Tip: Create a specific folder structure with Automator

PostPosted: Wed Dec 27, 2017 9:03 pm
by Antoinetteb
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.

Re: Tip: Create a specific folder structure with Automator

PostPosted: Thu Dec 28, 2017 12:48 pm
by gcoghill
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.

Re: Tip: Create a specific folder structure with Automator

PostPosted: Fri Nov 29, 2019 5:55 pm
by Trickyt57
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).

Re: Tip: Create a specific folder structure with Automator

PostPosted: Mon Dec 02, 2019 1:59 pm
by Mr_Noodle
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.