Trigger an Action Once Every Sunday?

Hello. I'm trying to trigger an action once every Sunday. I was trying a lot of solutions and then I found a function that would trigger on the first Macbook wakeup of the day.
Now I'm trying to add the condition that it should just be on Sundays.
I guess the first part doesn't look that bad but I don't know what variable to use for it.
Can someone help me please?

Keyboard Maestro Actions.kmactions (8.7 KB)

Good idea to use the wake trigger. At a quick glance, it looks like you've almost got it. I think the only change you need to make is to change this condition:

to this:

This would also let you simplify the macro a bit by letting you get rid of the corresponding Set Variable "Sunday" action at the end of the macro.

2 Likes

Thank you, I was looking for something like this. I still have to learn so much. Awesome. :slight_smile:

1 Like

Hi @Johnkree and @gglick, blind user here. Is it possible to get written description what I need to change in variable to get it to work? Perhaps, updated version of macro could be also great.
Thank you! :blush:

Hey @RDK I would like to help you but I abandoned the idea and started using Hazel 5 instead. I couldn't get the macro to do what I wanted. It's just too complicated and minor changes with the file naming need a lot of work. I could share the Hazel rules if you need them, though.

For my use case, I needed to get trigger work appropriately once a specific day.

I have considered trying out Hazel before, but trying to avoid extra application if possible. Perhaps you can convince me to finally give Hazel a chance.

What is advantages of using Hazel instead of Keyboard Maestro for your workflow?

In my honest opinion Keyboard Maestro is the best tool there is on Mac. I love it since day one and I have so many macros I'm using. But it is best at trigger based actions.
Hazel is a little bit better when it comes to "if this then that" automations.
I also wanted to avoid extra applications because of battery impact and RAM and all but neither Hazel nor Keyboard Maestro need recognizable system resources.

My main problem was: I needed an automation that archives files every Sunday. Now Sundays are very different. Usually they are family days, so it isn't sure that the Macbook is running at any given time. So the "Sunday at nine o'clock" trigger didn't always work. Then I tried to implement "when the Macbook awakes the first time on Sunday" action but this doesn't work, I couldn't find the mistake and I didn't want to spend much more time on one macro. So I got Hazel and it was very easy to implement. It checks if the files that are in the folder are older than 1 day AND if it is Sunday. If both are true it duplicates the files, renames them and archives them.

I modified your macro you posted and made it work. Can share it if you are still willing to accomplish this workflow in Keyboard Maestro.

Yes please. I would love to see where the error is...

Test Macro Every Sunday.kmmacros (3.4 KB)

Here you go. Maybe there are more elegant way to solve it, but this one works for me so long.

1 Like

Thank you so much... :slight_smile:

I'm puzzled why y'all are thinking it's hard to get KM to run a Macro "once every Sunday." Perhaps I fail to understand the problem because the solution seems simple to me. Have you considered the following? I apologize if I misunderstood the problem.

If your answer is "But that won't work if the computer is turned off or the KM engine is off," then I have ideas to fix that problem. But if that's not a problem, then you don't need those ideas.

I’m with you @Sleepy .

A Time of Day trigger would have worked, as well, but I stayed out of it as I thought he wanted something different…

I use time of day triggers dozens of times per day. They would work too. I'm not sure why I was recommending cron. But it works too.

This is exactly the problem. A simple time trigger will do it and I tried it, it works, the problem is that I can't predict if and when my Macbook is running on Sundays. Sometimes I sleep longer, sometimes I'm occupied with the baby, sometimes I'm on vacation with my family and so on.

I was looking for a solution that says:
Is it Sunday? Yes
And is it past 9:00 in the morning? Yes
Is the file in the folder older than today? Yes
If all three are a "yes" then make a copy of the files, move them and rename the new ones.

In Hazel I can do this with one "if this then that" rule.
In KM there are no combined triggers and my knowledge is too limited to implement it in other ways.

You can do anything with KM, but in this case you have to combine a trigger with a statement.

Technically not even Hazel (which is something I've never used) can actually have a trigger for your requirement because a trigger has to respond to a system event, and MacOS does not provide a trigger for two of your requirements. Therefore polling is required. Hazel may hide its polling in its engine, but KM makes you do the same polling explicitly. And I like having the power in my own hands, so I like KM's approach.

Here's one way to solve your problem, as I understand your problem:

Take action if day of week is appropriate Macro (v10.0.2)

Take action if day of week is appropriate.kmmacros (4.0 KB)

Of course you have to modify the folder or file name in the first action. And you have to enable the action. And you have to change the first Speak action to update the file's modified date using some method so that the conditions are only matched once per Sunday. And make sure that the time period trigger for this macro is longer than the time it takes for you to run your code to change the file's date. Otherwise you may end up running the macro twice simultaneously.

This is probably the simplest way to solve the problem. I have other more powerful ways, but I think you are looking for a simple way today.

P.S. This is the first time I've ever used ICUDateTime so there's a 10% chance I've done something wrong. Give this a try and see if it works. If it doesn't, I'll fix it.