Best Way to Identify Folder Trigger Path and Set as Variable for Further Use?

Howdy folks, I got curious about if I could improve on a macro I've been using for awhile and my testing led me to this neat idea.

The macro in question is one that monitors a folder for added files, and if the file is an ics Calendar file, it opens it in Calendar and adds it automatically.

But I got to wondering if I could monitor multiple folders for those files, and run the same macro regardless of what folder it was triggered by. So I can set multiple folder triggers, but how to know which folder was triggered so as to use that path later on in the macro?

Well I figured I could just search the %Trigger% token for a specific string to ID the path. For instance, when the Desktop was the folder trigger, that token returns the following information:

Anything is added to folder “~/Desktop” (ignoring partial files)

So I search that token using a simple RegEx:

“(.*)”

That gives me the path of the folder that triggered the macro which I can set as a variable for further use, such as in a For Each action.

It works quite well! For instance, now whenever I download an ics (calendar) file, in any folder I have set as a trigger, like Desktop, Downloads or my Dropbox Downloads folder, it gets that path from the token, sets it to a variable and then my For Each action uses that variable to search that folder for the relevant file.

You can see a simple demonstration of how the RegEx search is done below, as well as the macro I was tinkering with.

What I'm wondering though is if there's an even simpler way of doing this that I just haven't discovered? Perhaps a token I overlooked that returns ONLY the folder path in case of a folder trigger?

-Chris

Identify folder trigger path and set as variable for further use.kmmacros (3.6 KB)

Macro screenshot (click to expand/collapse)

14)Open- Calendar event files.kmmacros (9.7 KB)

Macro screenshot (click to expand/collapse)

There's nothing wrong with this method since it works as intended, but I would say there's a token and value better suited for this particular task. The way I'd personally go about it is with %TriggerValue% and the new-to-KM10 "Parent Path" filter:

Example Macro.kmmacros (2.9 KB)

3 Likes

That's a great method! I wasn’t aware of that new feature, thanks so much for sharing!

2 Likes