Request: Trigger when an item changes in a folder changes

It seems that the folder trigger can be used when an item is added or removed. It would be great to also be able to trigger it when an existing file is changed (i.e. edited and save, or overwritten).

I don’t believe the trigger can be used that way, and the only thing I can think of off the top of my head to accomplish what you need is periodic polling combined with comparing file modification time stamps. But to do that, you would have to save their timestamps in some format (probably a KM dictionary, or SQL database) to be able to compare the timestamp from the current poll to the timestamp from the previous poll. I’m just spitballing here though, no doubt others have better ideas.

I wonder if this might be a job for Hazel?

1 Like

Those were my thoughts as well.

1 Like

I'll speculate here that Hazel implements file change detection by regularly polling the file system. (Because if macOS was able to notify Hazel of "file changes" using an API, then KM would probably have implemented that trigger too.) And if polling is a valid solution, then KM can certainly do polling also.

I've achieved this, and the way I did it was by having the app that creates the file include the timestamp in the name of the file. (Some apps can do this.) All my macro had to do was check if the "most recent file" had a timestamp that was within 2 seconds of the current time. So I didn't need to use dictionaries or databases. It was that simple.

I think Hazel uses the File System Events API, based on the documentation I've skimmed read. I suspect that it's just a case of Hazel being more specialised in that area than KM.

This is fine for new files, but simply re-saving a file won't give it a new filename, as per the OP. Newly added files are detected by KM anyway.

I guess I stand corrected. I can't remember why I used a timestamp in my file names.

Wow, if Hazel has used a macOS API to detect file changes, then I'm disappointed that the KM Engine doesn't do the same thing. (I did look for Hazel documentation explaining how it works, but failed to find what you found.)

KM probably does, but just not with the same degree of granularity. I'm speculating, but I can't imagine it's constantly polling for changes across the entire file system. I could be wrong and often am.

I'd ask Peter but he has plenty to contend with at the moment.

1 Like

Some days it's hard to be clear. When I said "KM doesn't do the same thing" I wasn't referring to "use a macOS API" I was referring to checking the file's modification timestamp. I always read my messages before posting them and I try to resolve any ambiguities, but sometimes it's difficult being unambiguous.

1 Like

Hey man, I'm equally responsible for any misunderstanding. Don't take all the credit! :joy:

1 Like