Folder Trigger For Modified Files

Does the folder trigger not work when a file is modified?
Seems to only work for me when a file is added or removed

If so, any way to make it watch for modified files?


Not directly with Keyboard Maestro, no. Maybe Hazel can do it? You can do it by polling periodically to check for a modified file.

That's correct. Hazel can do that. (That the part I'm using Hazel for
[maybe the next version of Keyboard Maestro is able to do this as well ;-)])

Ouch. As of Sept. 2023, Hazel is $42 for a personal license.

In lieu of that, does anyone have any ideas for in effect creating an Observer in KBM that will trigger when any file in a specific folder is changed?

I use and highly recommend Hazel. It's developed by another indie developer, Paul Kim, who also has a long and reliable track record.

If you want to roll your own, here are two possibilities:

I've tried neither, but I have used launchd (employed in the second) several times.

I might think this all wrong, and might be overlooking something important, but if it is not necessary with immediate triggering couldn't this be done quite simply by using a periodic trigger? That at a set interval runs a macro making a record of the folders checksum, size (with content) or last modified date and then checks if the record have changed since last periodic interval.

These are all a but crude approaches, but here are my take(s) on this problem:

Detect folder change based on checksum:
This should be the most precise detection out of the three, but only really works on folders with small-ish amounts of data, as it takes a long time to calculate with large amounts of data

Macro File

IF folder content changes- based on checksum.kmmacros (3.7 KB)

Macro Image

Detect folder change based on folder size:
This approach should work if the file modification is expected to result in a change in file size.

Macro File

IF folder content changes- based on folder size.kmmacros (3.7 KB)

Macro Image

Detect folder change based on folder last modified date:
This approach is both simple and should be quite good at detecting any changes within the folder

Macro File

IF folder content changes- based on folder modification date.kmmacros (3.7 KB)

Macro Image

Thanks Jim.

I did more research into Hazel and the change I am trying to detect, a little bit different from @Mathias 's original question, is when a file is renamed -- unfortunately Hazel appears to miss those. Too bad.

Your other suggestions are certainly useful in a wide variety of circumstances that answer my question of a less pricey solution.

The first link, to Ask Different, has a variety of useful techniques and discussion. Nice find.

The second is a very well written tutorial into a complex subject. Many years ago I wrote a tutorial on using cron and crontab for "Inside SCO Unix" magazine, so I have some familiarity with the subject. I added a launchd job to my Mac a couple of years ago when I was using Trello for my To-Do list, to create a fresh list for me every morning using calls to the Trello API.

Because I'm looking for when a file is renamed, it doesn't look like any of the proposed solutions will work for watching files but watching the folder may work.

Thanks Alexander,

I appreciate your putting that together. It's the direction I have been leaning in. I'll give it a try.

Five seconds seems short enough that the change will be noticed by the system pretty quickly. If I am doing things rapidly, I suppose in my workflow I might trip over not having action automatically taken fast enough, but I think that will be rare.

Will that create additional overhead on an already taxed system? I don't know.