Macro That Monitors Different Folders

Hello!

I have a macro that has a trigger when a file has been uploaded to a folder.

The folder structure that I'm monitoring has the month name in it, for example,:

/Users/dayaketu/Library/Mobile Documents/com~apple~CloudDocs/Audio Shares/Free Buddhist Audio Files/FBA Podcasts Audio/2023/**June**

Now, I want to monitor for files for the upcoming months, and I can easily add another folder but with July, but I've seen on the error logs that of course, it errors out every second when KM tries to check, as the folder does not exist yet.

So, I'm sure it's not good practice to have an error every second and that might make KM slow or something, so my question is that if I can somehow improve the macro to check on a folder that has a variable and that variable has the current month or something.

Thanks! :blush:

Agreed.

No, you cannot include a variable in the path, as then every change to the variable would change the trigger, which means the trigger would have to watch both the folder, and anything that could affect the token expansion of the path.

What you could do is change the macro with another macro that is triggered on the first of the month.

If your Mac is always on, then you can use a Cron trigger to trigger at 1am on the 1st of the month.

If your Mac is not always on, then you need to have a periodic trigger (with whatever period you can live with, maybe once per hour?) that checks if the month is different to the previously set month.

Then you need to adjust the trigger via AppleScript like this:

tell application "Keyboard Maestro"
	set m to macro "Watch Folder"
	set t to trigger 1 of m
	set x to xml of t
	tell application "Keyboard Maestro Engine"
		set x to search x for "/Downloads/\\w+" replace "/Downloads/%ICUDateTime%MMMM%" with regex and process tokens
	end tell
	x
	set xml of t to x
end tell
2 Likes

Wow, this is so useful @peternlewis!

Thanks for the help! :blush:

1 Like