Hazel to copy files into a subfolder based on tag

I’m looking for a way for Hazel to copy file into a folder OR create a new folder (set name based on tag) and copy the file into the folder based on the tag of the file.

e.g. I tag a file as “receipt”. Hazel will copy that file into another location and store it inside a folder called “receipt”. If the folder isn’t there, Hazel creates it first, then copy the file into it.

Anyone could help please?

Are you sure it isn’t just going to create the folder for you if required?


I want to create folders based on tags. This article doesn’t talk about that, does it?

I think you’d need to script this. Hazel could monitor the folder, add the tag, then do the rest with something like AppleScript. It would be nice if Hazel could use tokens to create the folder, but I don’t think a native method exists other than to copy to an existing folder.

Have a look at processing subfolders and see if that might work for you.

OK, thanks. Pity because I’m not good in creating scripts.

In that case, try this:

  • Create a primary folder (Folder 1) for monitoring you documents you want to copy and file.
  • Create a subfolder in the primary folder (Folder 2) for receiving a copy of the original document, since I dont think Hazel will let you duplicate the file in place.
  • Rule #1 in Folder 1 : “Copy to folder” (Folder 2)
  • Rule #2 in Folder 2: “Sort into subfolder” with pattern tags_name, which will create a new subfolder in the Folder 2 based on the tag and name of the file.

You will see in the pattern field there are many tokens available to rename the folder based on the file attributes. You can do the same with naming the original file and the copied files.

This should get you where you want to go without scripting.

1 Like

No - the part of the discussion I linked to noted that if the folder doesn’t exist, Hazel will create it. I had envisaged you were already looking at using one of the tag tokens; much like @evanfuchs shows in his example rule above.

Thanks @evanfuchs.

I guess my biggest issue here was that I was unaware of the availability of the token “tags”, as it’s hidden by default under “other” and I was simply uninspired to check it there. I will follow your instructions to see if I get a good result.

I’m still having issues and I don’t think @evanfuchs solution addresses what I intended.

The workflow I want is the following:

Folder 1 contains tagged files

Hazel copies all of the tagged files into another drive, into folder 2. Inside Folder 2 Hazel will create folders having as name only the tag of the file.


  1. Folder 1 contains ten files tagged as work
  2. Hazel copies all ten files to Folder 2, create a folder called work (Folder 3) and add all the ten files into it.
  3. If the folder work (Folder 3) already exists in the destination, all new files tagged as work in Folder 1 are moved into Folder 3.

How can I accomplish that? Here’s the screenshot of my current, wrong setup.

My workflow involving AppleScript and Hazel:

Really interesting. I’m just not succeeding with the export tokens. In your example, you show . Tag as the export token to be used. It doesn’t create a folder based on that.

I’ve also added the correct path I believe to the scripts. It’s in my iCloud folder:

–get a list of all primary directories

do shell script “ls -d /Users/bernardo/Library/Mobile Documents/com~apple~CloudDocs/Studies/*/”

–transform into AppleScript compatible list

set theFullList1 to paragraphs of result

How does the solution I described not address what you are intending to do?

If you create two separate rules, Rule #1 for Folder 1 to copy the file from Folder 1 to Folder 2, and Rule #2 for Folder 2 to sort into subfolders of Folder 2 (Folder 3) based on the file tag, it should work even if Folder 3 already exists.

For example, if you save “File 1” with the tag “work” to Folder 1, Hazel will copy it to Folder 2, then it will move File 1 from Folder 2 to existing /Folder2/work/ or create /Folder2/work/ if it doesn’t already exist.

Sorry I didn’t address the issue directly with you before. I should have done that.

You recommend the pattern tags_name. That creates individual folders for each file name. It does not do what you say it should happen:

“if you save “File 1” with the tag “work” to Folder 1, Hazel will copy it to Folder 2, then it will move File 1 from Folder 2 to existing /Folder2/work/ or create /Folder2/work/ if it doesn’t already exist.”

Your pattern creates folders such as File 1, File 2 (or whatever the file name is). Removing “name” from the pattern also doesn’t help, and I have no clue why. Hazel does not create folders if I remove the “name” pattern. It basically ignores the “tag” pattern.

@Maksim do you have any input on my post above? Thanks :slight_smile:

Strange. It does for me. If there are multiple tags, it creates a single folder named by the tags names separated by commas. Like this /Folder2/work, tag2, tag3/

Are you sure you are grabbing the tags token (in blue)?

Yes, I’m pretty sure. Also sure that there are matching elements in the folder (red label)

I would change the match condition to something else, like Date Last Matched is blank, to see if the Sort into subfolders works. Then you can work on the matching.

I’ve already tried with Name is not blank. No success.

Sorry, I can’t duplicate the problem. Sounds like you have a matching problem, not problem with the actions after the match. You can troubleshoot the matching using the Preview button.

I don’t have a matching problem