Organize the ~/Downloads Folder As Items Are Added

I know you can do this in Hazel but I like to try to do as many things in KM before getting another tool.

I'd like to watch my Downloads folder for newly added image files and put them in a subfolder called Images. I know you can use "files added to a folder" as a trigger but don't know how to filter it/make a rule so that it only works on image files with .png, .jpg, or .heic extensions...


You're very close to a solution. The solution is an IF statement in the macro that checks the file extension. If it's not the extension(s) that you want, abort the macro, otherwise move them. Give it a try and if you can't solve it, I'll help.

Thank you. My trouble is I can't figure out which Condition to check in the If then else...

Ok I'll paste a brief example here...

There are several ways to do it, but here's one of them. (Sorry for the spelling error.)

1 Like

Thank you. I'm still missing something...

You are getting close. I can see two probable errors. It's not really your fault because my advice was incomplete. I was in a rush. Here are the two issues that I see.

  1. You are using a variable called DownloadedFile which doesn't exist.

If you read the following page you will see where the filename is stored when you create a trigger like you are doing....

It's stored in a token, not a variable. So instead of specifying "Filter Variable" you should specify "Filter Text" and include the token (with percent delimiters). Can you make this change?

If you are still stuck with those instructions, show me what you did.

  1. In your move statement you also need to pass the full path of the file. You have a blank line there. You need to insert the same token here.

P.S. I guess the Cancel action isn't needed. It doesn't hurt.

Sorry, there is still a bunch in there I don't know how to do...

Okay, I will write the macro for you. Sorry, I thought you could handle that advice.

I'm really trying my best but I struggle to figure out the variables. Sorry. Thank you so much for your help. I tried to make it on my own before coming to the forum and asking for help.

It's okay. Sometimes I give full solutions, sometimes I set a direction. I made the wrong call in this case.

Okay, I wrote it, now I have to test it before I upload it. Okay here it is. Please note that I used my own folder instead of the folder you wanted to use. I trust you can make that change. Also, I noticed that the extension is case sensitive, so most likely you want to include upper case and lower case versions of "JPG" and whatever other extensions you want.

If this doesn't work for you, let me know, I can make more changes.

Move Files from Downloads into ~/Data/Downloads Macro (v10.0.2)

Move Files from Downloads into ~-Data-Downloads.kmmacros (3.2 KB)

In other words, what you probably have to change is from "~/Data/Downloads" to "~/Downloads/IMAGES" and also change from "JPG|PNG|HEIC" to "JPG|PNG|HEIC|jpg|png|heic" or whatever file extensions you want, both upper and lower case.

There are ways to improve this macro, or to write it differently, but I provide only one solution when I provide solutions.

OOPS, you can delete the DISPLAY TEXT action. I was using that for debugging.

1 Like

Awesome. Thank you so much for your help! This taught me a lot about variables. Thank you again for your time.

If you need a lot of file extensions, plus all their upper/lowercase variants, this macro could be improved. But for just a handful of variants, this is probably good enough.

This seems to work fine for one file but I'm trying to figure out why it's getting bugged out on multiple files being added at the same time... Getting this error if more than one image is added to the downloads folder...

CleanShot 2021-12-17 at 13.57.03

The Move action may have failed if it was unable to move the file, such as what would happen if you already have a file by the same name in the destination folder. Did you check if you have duplicate files?

Anything can be fixed, but I didn't anticipate the case of duplicate files, and you didn't indicate what you want to happen when a duplicate filename exists.

Hey Guys,

Keep in mind that apps often write invisible files when downloading and then rename them when the file finishes writing.

You can end up with very unexpected conflicts.

When testing it's a good idea to log all the file paths, so you can see exactly what you're working with.