Folder trigger not ignoring partial or changing files [SOLVED]

I have this simple macro as a test
image

and I purposely created a 5GB file to test this, moving it to a different internal disk. Dragged the file to the Desktop and it started copying. At first KM didn't do anything, as expected, but suddenly, while the file was still copying, it moved it to my Inbox Global folder. I could still see the progress dialog and it indeed moved the whole file to Inbox Global, but shouldn't it wait until the file is 100% in the Desktop?

I do have Hazel, but I'm trying to migrate certain things to KM, just because it's easier for me to have everything in KM and leave only very specific things in Hazel.

I'm not sure what might explain your issue, but I do see a possible problem with your macro. I.e., your macro has a loop that moves all files on the desktop to a folder whenever a single file is added to that Desktop folder. That's risky. I think you should move only the ONE file that triggered the macro. Your way, you could get lots of errors if apps or macOS create more than one file on your desktop at similar times.

There's a very slim chance that if you fix this, your problem might go away.

2 Likes

The problem is that the OS will tell apps it's done when it's not done. If you want to prevent this, you need a loop that gets the size of the file, waits some amount of time, gets the size to a different variable, then compares them. The macro should only continue when the two sizes are the same.

(I ran into this trying to trigger on things copied into the Applications folder; they were nowhere near done when the macro continued.)

-rob.

1 Like

I was reading about launchd (I have no deep understanding on how it works, even though I understand that it can be used to run some actions) and that was mentioned as well, the comparison workflow. Will try that.

So I guess I need to combine this with what @Airy said?
But at the same time, I always want to move any files added to the Desktop, because that's exactly the role of my Inbox Folder.
If I add 2 files, will KM know that 2 files triggered the macro?

I'm aware of the %TriggerValue% token, but in this case how would I use it? Also with a For Each?
I can't seem to understand how that would work, especially with multiple files being added...

Then what is the goal of the "Ignore" options? Shouldn't it be to ignore files until they are complete?

Ok I was doing some extra tests and yes, KM knows that 2 files triggered the macro so I will keep testing and see how it goes. It seems very straight forward. I just need to find a way to get the file size, which should be easy.

I assume that's the goal, but from the wiki:

"and can ignore partial files (files with extensions that are known to be “in progress” files)."

So if your file didn't have one of those extensions, perhaps that's why the trigger fired?

-rob.

1 Like

I was using a simple ZIP file, which I would assume would be one of those, but who knows?

I will try the other approach. Will keep you posted.

You can get it with the Get File Attribute action in Keyboard Maestro, or a number of ways in the shell.

-rob.

Yes, I found that action and now I'm in the process of understanding the workflow. I'm getting there :wink: Thanks. A few more minutes...

I guess something like this?

image

I tested it and it works!

No, it's more like downloading files (the name temporarily suffixed with "download", IIRC), or files suffixed with ".inprogress" or similar. KM knows of a bunch of temporary extensions which it should treat as "in progress" indicators.

1 Like

Oh, I see. Like when I'm downloading something from the internet or something.
Thanks for clarifying. :raised_hands:

So now that it seems to be working with the workflow I shared on my previous reply, since I have 4 folders that should move all files to Inbox Folder, should I have 4 macros, or does this work without any issues using a single macro?

image

Ok I was testing a very extreme workflow:
Created 4 different versions of that 5GB file with different names. Started copying them to those 4 locations.
image

Now, since it seems to "stall" for more than 5 seconds, all unfinished files were already moved to Inbox Folder, even though they are still copying...

Each time a new file is added, a new instance/copy of your macro will be created. So please stop thinking of using a For Each action. Using a For Each action will only cause yourself problems.

1 Like

Yes, you need to set your "check" time to as long as you can get away with without it impacting your workflow -- bearing in mind that different processes can write files in different ways, some continuously and some in spurts with pauses.

I'd start with a 30 second pause in the "check" loop -- but I frequently copy from slow network shares and similar.

It'll work -- but, as @Airy says, don't use a "For Each...". When something is added to any of those "watched" folders the full path of the added item is the %TriggerValue% of the executing instance. Put that %TriggerValue% into a local variable as the first action (always good practice), then use that local variable in all your checks and the final "Move" action.

If you leave the triggers set as "ignore partial or changing files" your macro should properly cope with both files/folders KM does recognise as "in progress" (via the trigger) and those it doesn't (via your size checks).

1 Like

Folks have explained the issue. Instead of moving all the files from your desktop whenever any file is added to your desktop and stops changing, the action should move the %TriggerValue% file.

Otherwise, while you are copying that 5GB file, if you move a 1k file onto the desktop, then the 5GB file will be moved as well.

Note for those visiting this thread in the future, and why it's not ignoring partial or changing files:


This is actually my macro to do what I wanted to do (no For Each involved)

Move files and folders to Inbox Global automatically.kmmacros (23 KB)

Keyboard Maestro Export

The 5GB example was, as mentioned, an extreme example, because:
1 - It's very rare that files even go to those folders anyway, especially the Desktop and Downloads, because most of my apps that had the Downloads set as the default folder, are changed to Inbox Folder anyway. I also never add anything to the Desktop for many years now.
2 - The files that end up on those folders in iCloud, especially the Inbox Folder in iCloud, are usually very small files such as images or small audio.
3 - Even if I had files as big as 5GB, I wouldn't be copying 4 of them at the same time anyway.

So let's see how this goes with this set up. I made it pause for 10 seconds, which seems to be more than enough. Only time will tell.

Thank you all for your help :raised_hands: