Trigger macro from new file added to folder, ONLY when download is complete

Hi there, I'm trying to set up a macro that watches a folder for new video added to it and then renames it and puts it in the correct folder. I already have the latter half of the macro working, but the issue is I'm downloading the files into this folder (not adding) and the macro gets triggered on the incomplete file. Best way I can think of to fix the issue is to check the file size and then run the macro once it's finished DLing.

I have a pretty good work around in Hazel by having it move .mp4s into a KM watchfolder ONLY if the file size is bigger than 0, which seems to work for my main download method. When I try the same thing in KM though it doesn't work, I think because it's reading the file size more accurately than Hazel and so >0 doesn't cut it. It seems I need to know how to have it check the size until the size stops changing in order to fully do this in KM.

Any help would be much appreciated!

In Hazel I tend to use Not Modified Within Last X Minutes as a condition. What about using such a condition in KM for your videos?

You don't show how your Macro is triggered, but if you want what you state above, then you do NOT want to use a For Each Action on all files in the folder.

For a good example, see

Select "ignore partial file":


From the Keyboard Maestro Wiki:

You can have the trigger ignore partial or changing files, so for example if a file is being downloaded or copied in to the folder, the trigger will wait until the download/copy has completed and can ignore partial files (files with extensions that are known to be “in progress” files).

Hi all, thanks for the suggestions, I didn't know about %TriggerValue% and that has just radically simplified my macro, but the problem remains that the macro is triggering before the download has completed. And yes, sorry for not showing this but I am triggering the macro by watching the folder, checking "ignore partial files" doesn't do anything.

How do I add conditions to this workflow? I would love it if it only did this with .mp4s for example. The way I used to do it is using a split path I would store the extension into a variable, but I can't get the split path function to work with the trigger value? How do I have it rename the file while preserving the original extension? You can see in the screenshot that I've just written in .mp4 but I'd rather this is flexible.

How do you know this?

This works for me. Please let us know if it works for you.
I didn't have any issues with partial files, but I did use a different trigger option:


MACRO: Move Files Added to (Dropped on) Folder [Example]

Boom, I got it. The changing files element is important, forgot about that when I created this WIP macro. In combination with the %TriggerValue% it seems to avoid the pitfalls I was experiencing before. Was also running into the issue where creating a new folder in the directory to sort it was then triggering the macro twice, so I had it disable the macro once it gathers the necessary info. For me this works really well as I don't want this running all the time in the background, I'm running it one file at a time as I DL + generate the naming I want. Thanks for all the help!

It's your macro and your design, but IMO the ~/Downloads folder should be limited to exactly that -- used ONLY to receive downloads. I'd create your "Destination Folder" somewhere outside of ~/Downloads, like ~/Documents/Videos.

One reason is that I see ~/Downloads as a temp storage location, in which everything should either be moved to another folder, or deleted. So I routinely move the contents to the Trash.

Just my 2¢, of course. :wink:

For sure, the final destination in my case is a company server so I've always been hesitant to use macros in those directories just in case the worst were to happen somehow. I just move them in batches so I have time to check them over before sharing.

Just adjusted this, figured I might as well share. Was still having issues with larger/longer downloads.

If the macro is being triggered before the download is complete, then you should report it as a bug, so @peternlewis can investigate.

Also, I see two problems with your revision using the Execute Until Action:


  1. You should add a Pause at the bottom of the loop, say ~ 0.2 sec
  2. Checking for non-zero does not mean it is finished.
    • You should check until the file size does not change over some period of time.
    • It is hard to say how much time since you are dependent on the Internet.
    • But I would start with 1 sec and see how that works
    • Of course, you should not need to do this. That's why a bug report is needed.

Yeah I think I get why. It works for me because of the download method I'm using. Typically use 4K Video Downloader and it creates one or two .part files alongside a 0 byte .mp4. So it's either 0 bytes or the download is complete. Figured .part would be considered a "partial" file in KM, but I guess not? Still don't really get why only the longer downloads need to have the size checked, KM is pretty fast at recognizing new files added and none of these downloads are exactly instant so that seems weird to me.

Good call on the pause thanks.