Folder Trigger Only Triggers With Copied Files Within Finder - Does Not Trigger When Files Are Saved There From an Application

I'm trying to setup a macro where PDFs added to a specific folder with a specific name get moved to another folder. I've seen a number of examples of that around the forums, but I'm stuck on the trigger action itself.

The macro is set to Trigger when a file is added to the folder. If I copy-paste a file there from within Finder, it triggers. However, if a program saves a new file there... it does not trigger. I've tried this with multiple different programs, downloading files from a web browser, and changing the subconditions of the Trigger (trigger all changes immediately, ignore partial files, etc.), but it just won't activate when a program saves a file to the folder. Only if I copy a file there from the clipboard.

Currently running KM on a Mac Studio, OSX 12.6. Keyboard Maestro version 10.2

Thanks for any help on this.

EDIT: Nevermind on the below secondary issue (the above issue is still relevent though); it was just the result of my lack of patience. Setting the trigger to "ignore partial or changing files" does make it all work as expected, I just didn't wait long enough to see if things were following through in the end. But I'll preserve the message below in case another similarly impatient KM user experiences this.
A separate issue is that it doesn't seem to wait until the file is done copying to move it. The attached macro has a manual 1 second delay to give time for the file to finish copying before it attempts to move it. Without this, KM seems to try and move the file immediately (again, even if I tinker with the trigger conditions to ignore partial files, etc.) and then fails to complete, having copied a partial file to the new folder. I then also get a KM error message that reads "File action failed because destination already exists." This feels like a bug in the trigger?

Copy Scores and Parts to Folders.kmmacros (2.5 KB)

Create a macro that simply displays the trigger value of the saved files.

See what's actually happening on your system.

Chances are that you're getting more than one file, because the app creates a temporary file while downloading or saving it and then renames it – so KM attempts to operate on more than one file.

Thanks for the help! I did solve that problem already (and using the Display Text action to confirm what the TriggerValue was, as suggested here)

The other issue of the macro simply not triggering at all when files are saved there is still a problem, though

KM depends on the app to provide the "I've not completed yet" signal -- for instance an .inprogress extension on the partially-written file that changes when complete. What you can do is check yourself -- one way is to have the macro trigger normally and then pause, checking the file size attribute every second until it no longer changes. You'll find a couple of other methods if you search the Forum.

It's a problem with how the OS reports a "folder change" -- the event fires when the change starts, not when it stops.

What's the offending app?

I tested this with Sibelius (a music notation software), as well as Word, Excel, and Google Chrome - none of them would trigger the macro. Only doing a copy-paste from within Finder to the macro’d folder triggered it.

Hmm.

I don't know what to tell you about this...

On my system Microsoft Word, TextEdit, Script Debugger, and BBEdit all fire off the folder trigger when saving documents.

It's a trifle slow, but it works.

macOS 10.14.6 Mojave running on an older i7 MacBook Air.

Bummer. I did try and wait a while just to ensure it wasn't my impatience causing the problem again, but no dice.

Guess I'll have to find an alternative to triggering this then. Perhaps there's a way to have it check the folder every X minutes while a specific application is open?

Sure.

Create a macro in your app-specific macro group that has a periodic trigger.

You also may have a couple of alternatives.

  • A AppleScript Folder Attachment Script
  • A LaunchD script

Ask about those over on the Script Debugger Forum, and you may want to peruse MacScripter.net

Are you sure that your Macro is in a Group that is enabled in all Apps? Looking at your original Macro, it seems like it is only enabled in Finder and Font Book. Try putting the Macro into your Global Macro Group.

image

Just testing this myself - having a similar folder trigger Macro in my Finder Group does not work if saving from other Apps. It only works if I am in the Finder. Putting the same Macro in a Global Macro Group and it fires whatever App I save from, to the Folder.

2 Likes

THANK YOU! This absolutely solved the problem. Feels like a silly oversight on my part, though I guess I assumed the macro would still trigger since the actions are happening through Finder, rather than necessarily needing Finder to be in focus. In any case, problem solved now!

1 Like

It was! 

But don't feel bad – I've made that one before myself a time or two. :sunglasses:

This won't be the last time you have a V8 moment with Keyboard Maestro...