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?