Macro to run once a month

I am relatively new to KM. I would like to write a macro to run Malwarebytes on my Mac once a month automatically. I can’t visualize a method of setting a trigger. Any suggestions? Thanks.

Since the KM Periodic Trigger does NOT have a period > Hours, and the At Time Trigger max is once/week, you will need an external method to trigger running the KM Macro.

I have not done this, but it looks like one approach is to use the Calendar app with Automator (or an AppleScript).

Automate your Mac to Run Scheduled Tasks

You would create the Automator workflow, or the AppleScript, to execute the KM Macro, and then schedule it in Calendar.

Again, I have NOT done or tested this, so it may, or may not, work.
Hopefully, it will be a good starting point for you.

One solution would be to use crontab. Obviously use at your own risk, however there's little harm you could cause.

Firstly, you'll need the UUID of your macro.

Open up and type paste in the following

(crontab -l ; echo "0 0 1 * * osascript -e 'tell application "Keyboard Maestro Engine" to do script "YOUR_UUID_HERE"'")| crontab -```

Be sure to replace YOUR_UUID_HERE with the UUID you copied. Also be sure to retain all the quotes in the command I gave you.

The way this is set is to run on the first of every month at 12am. This won't wake your computer to run it, so you'll have to be sure it's on. If you want to change the time, the first 0 is the minutes and the second 0 is the hours of the day (24h time). If you were to change it to "30 15 1 * *", that would be 3:30pm on the 1st of every month.

Excellent. I never heard of it.
It is always good to learn something new. :smile:

I’m just betting that we could build a KM Macro to facilitate this.
Any takers?

While I love KM for automation, using crontab + KM might be a weird solution, especially for things that run once a month. Another thing you might want to look into is launchd for MacOS’s solution to services and recurring jobs. Writing the XML is a bit of a pain, but there are apps out there like LaunchControl that help with building it.

Sorry, I wan’t very clear.

What I meant was using a KM Macro to build a shell script that runs crontab, and then executes it. Like many users, I shy away from creating shell scripts on my own.

But a KM Macro that asks the user for:

  • Macro UUID (or get it for him)
  • Scheduling details

then builds a script that is executed.

Just an idea. Maybe not feasible.

Feasible sure, but seems like a lot of work for a one-off. Crontab is a service that runs on your computer that runs scripts on a scheduled basis. The command I gave above is just a one off to update crontab as a one-off and then you’d never need it again. I suppose if you plan on creating lots of scheduled events like this, a KM macro could be useful, but seems like one of those cases where you’re spending more time writing the automation than just taking care of it yourself :slight_smile:

Thank you all for the prompt replies. Helpful thoughts both from a general learning perspective and about my specific problem. Wow, have I a lot to learn!! I haven’t felt so much at sea since I taught myself to program in Postscript in 1995.

Wandering around in the online helps I found the discussions of the Date/Time functions. Could you trigger a macro to run once a day, then in the macro extract the day number as a variable and test it for the value “15” in order to then run Malwarebytes on the 15th of each month?


I think that should work, using the “At Time” trigger.

Here is my simple solution tested as far as I can without waiting for another month to go by.


Looks pretty good, but I do have one suggestion.
Instead of "matches" (which means a RegEx match), you may want to use a simple "Is", which is a direct string comparison.

Thanks. Typical unschooled programmer mistake … try things until something works and then use it.

1 Like

Don’t feel bad - I was setting a variable to “short date” and then extracting the day with a regex until I saw your much better approach w/ ICUdate. But as you said, I got it to work and then used it!! I’ve changed it now to do what you do, though.

What, you mean there’s some other way to do things? :open_mouth:


1 Like

There was an error in my original concept: As previously written this "Once a month" macro will skip the month if my Mac is turned off when the macro would otherwise run. Here's a better solution that checks every day to see if it has run for the month and proceeds accordingly........

Better still is:

The calculation DAY() = 15

OK, better by some definition, since really any solution that works correctly every time is “perfect” already.

Your comment about matches is important since one might one day change it to go on the 5th of each month, and matches would be the same as contains which would trigger on the 5th. 15th and 25th (or worse, if you triggered on the very natural 1st of the month, it would trigger on the 1st, 10th, 11th, …19th, 21st. and 31st) - both of these could be bad and would definitely be confusion.

  • text %ICUDateTime%d% is 15
  • calculation DAY() = 15

are both correct every time and work for any day of the month selected, so they are both correct and robust.

I use a program called Lingon X for creating launch daemon XML - well worth the small amount of money.

This is an old post from Dec 2016, and since then KM has really improved.
The Cron trigger can now do exactly what you want:
@monthly — same as 0 0 1 * * (midnight at the start of the 1st of each month).

I added this post because I was looking for this very trigger, and this is the thread that as on top.

In my case I wanted a trigger for the last day of each month:
0 0 -1 * *


Very cool Peter @peternlewis! :+1:

Many thanks for giving us such a great tool that is so easy to use.


You cast your bread on the waters and you never know when it will return.


1 Like

Thanks for your help in the past.

Quick question:

I can come up with numerous ways to make something happen 10 (or N)
times. What is the simplest way?