Repeat quick macro N times

Hi,
Is it possible to set up a macro that asks me for a number of repetitions and then repeats the currently recorded quick macro for a specific key that many times? It has to be a quick macro, or an ad-hoc recordable macro anyway, I usually want this for some line manipulation where I can plainly see how many more times the macro has to be run.
I've tried to achieve it by making the macro type Option-Q (my run quick macro key) N times, but it just types the corresponding symbol instead. Trying to trigger it by macro shortcut key doesn't do anything at all.

Sure this is possible — or perhaps not. Did you try using the Prompt for User Input and Repeat actions?

Without seeing what you're actually working with, it's difficult to say what could be happening or why. For this reason, it's usually best to upload your macro along with a screenshot of it.

Some helpful tips:
How to Post/Upload Your Macro to the Forum
How Do I Get The Best Answer in the Shortest Time?

1 Like

The repetition part is not a problem, I just can't figure out how to get it to repeat a pre-recorded quick macro. Sure, here is one of my attempts:



oscu0 quick macro repeat.kmmacros (4.2 KB)

1 Like

If we try the Trigger macros by Hot Key action by itself (using "Try action" under the action's cogwheel), an error is logged.

"Trigger Macros by Hot Key failed to find any active macros. Macro “Trying” cancelled (while executing Trigger Macros by the ⌥Q Hot Key)."

This suggests that the action only searches for macros in the macro list, and is not aware of quick macros. (If this is correct, perhaps the Wiki's entry for the macro should mention it; also the heading is wrong. @peternlewis)

@oscu0, since your macro incorporates a user prompt, I wonder if maybe your intention with the macro is going to be a little bit fancy for a quick-and-dirty Quick Macro, and that a full macro might be better suited. I could be completely wrong there, but I mention it because Quick Macros are best suited to very simple ad hoc tasks and their capabilities will be more easily exceeded.

Someone else here may well be able to advise you better on this, however.

1 Like

Yes, and I'm not sure why it isn't working for you. If I make something similar to yours and enter 3 at the prompt my Engine.log shows:

2024-12-13 19:02:00 Execute macro “Scratch 3 ” from trigger The Hot Key ⌃⌥⌘F10 is pressed
2024-12-13 19:02:02 Execute macro “Record [Quick Macro]” from trigger Trigger Macros by Hot Key
2024-12-13 19:02:02 Execute macro “Record [Quick Macro]” from trigger Trigger Macros by Hot Key
2024-12-13 19:02:02 Execute macro “Record [Quick Macro]” from trigger Trigger Macros by Hot Key

So check your Engine.log (~/Library/Logs/Keyboard Maestro/Engine.log) and see if there are any clues there.

What does your Quick Macro do? Does it, perhaps, rely on some context that isn't present when you are running it?

I suggest you start again, and start simple. Just have your Quick Macro record you typing 1 into a document, then see if you can wrap that in a repeat to type multiple 1s.

@Nige_S I did test it with typing a key stroke instead of running a macro and it works. At the moment my quick macro consists of typing '111' and it is not being triggered by my repeat macro. Could you please share yours?
The log looks like yours, it's just that the macro I've recorded doesn't run.

@kevinb the quick macro doesn't include a prompt, at the moment it's just typing '111'. The prompt is for how many times to repeat the (pre-recorded) quick macro. Ad hoc quick list manipulation is exactly what I use quick macros for, I just want to be able to tell KM to loop the quick macro a certain number of times.

If your log looks like mine then your Quick Macro is running, just not doing anything.

"Scratch 3" is simply

...and when I run it with ⌃⌥⌘F10 the log has

2024-12-13 19:02:00 Execute macro “Scratch 3 ” from trigger The Hot Key ⌃⌥⌘F10 is pressed

appended.

When I then entry 3 in the prompt and hit return it executes the Quick Macro 3 times by Hot Key and the log shows

2024-12-13 19:02:02 Execute macro “Record [Quick Macro]” from trigger Trigger Macros by Hot Key
2024-12-13 19:02:02 Execute macro “Record [Quick Macro]” from trigger Trigger Macros by Hot Key
2024-12-13 19:02:02 Execute macro “Record [Quick Macro]” from trigger Trigger Macros by Hot Key

So check your log file again. If it is similar to mine it's the Quick Macro that's the problem, not the "Repeater" macro.

AFAIK Quick Macros can only be properly run on the machine that created them. Your macros, linked above, do work for me in that "whatever" happens n times but I just get a bunch of window flickering. So you'll have to describe what it is supposed to achieve -- perhaps there's a clue there (probably contextual).

Yes, I did get that much, but perhaps only that much, then! :laughing:

@Nige_S if I reference the "record quick macro" key, it does work, and indeed does nothing. if I reference the key with which the quick macro is run, it can't find it. Having spent more time in the log, I see that the recorded quick macro is called "Quick Macro [Quick Macro]", but I cannot run a macro by that name either. I've tested it with simple input and my repetition code works fine.
UPD: I can also add it to the menu bar item or to the global palette and it also shows up by the same name, but I can't seem to select it as the object of the Execute a Macro action

That means the real question is how do I execute a quick macro currently recorded on a hot key?

please excuse my tardy replies, I'm currently writing my thesis, only get to play around on the weekend :slight_smile:

Quick Macros aren't "proper" macros in that they aren't listed in the Editor -- the "recorder" is, but not the "product".

It should just work -- if the macro runs when you type ⌥Q it should also run when you send ⌥Q from the KM action. Try it again and post the relevant lines of your Engine log.

The recording macro is called "Quick Macro", and that's what you need to look for in the Editor. One thing to check is the Group that macro is in -- is it enabled and available in the context you are trying to run the macro?

@Nige_S here's the relevant log excerpt:

2024-12-20 23:11:59 Execute macro “Quick Macro” from trigger The Hot Key ⌃Q is pressed
2024-12-20 23:12:02 Execute macro “Quick Macro” from trigger The Hot Key ⌃Q is pressed
2024-12-20 23:12:08 Execute macro “Quick Macro [Quick Macro]” from trigger While the Hot Key ⌥Q is down
2024-12-20 23:12:09 Execute macro “Quick Macro [Quick Macro]” from trigger While the Hot Key ⌥Q is down
2024-12-20 23:12:12 Execute macro “Quick Macro [Quick Macro]” from trigger While the Hot Key ⌥Q is down
2024-12-20 23:12:58 Execute macro “Repeat Quick Macro” from trigger The Hot Key ⌃⌥⇧Q is pressed
2024-12-20 23:13:01 Action 9550244 failed: Trigger Macros by Hot Key failed to find any active macros
2024-12-20 23:13:01 Trigger Macros by Hot Key failed to find any active macros. Macro “Repeat Quick Macro” cancelled (while executing Trigger Macros by the ⌥Q Hot Key).
2024-12-20 23:13:40 Execute macro “Quick Macro [Quick Macro]” from trigger While the Hot Key ⌥Q is down
2024-12-20 23:13:41 Execute macro “Quick Macro [Quick Macro]” from trigger While the Hot Key ⌥Q is down

First two lines is me recording a random macro that types some text.
Then the macro runs thrice from ⌥Q
Then I call the repeater action, it can't find a macro at ⌥Q
Then I run the macro again just fine from ⌥Q twice, it's not emptied or deleted or anything.

Perhaps I am missing something obvious about how they are set up. It does appear to be looking up a macro by the correct hot key...

There's the clue -- "While the Hot Key ⌥Q is down".

Uncheck "Enable Key Repeat":

...and you should be golden. Behaviour replicated, and fixed, on two machines here.

I don't know why it is erroring with "failing to find", but "Key Repeat" is not much use in this situation anyway.

2 Likes

I do not fully agree it is no use here — while I haven't actually ever held down the run macro key to keep repeating it I feel I might try to now that I know about the possibility :slight_smile: Then again, you can't hold down @q in vim to repeat the macro, so I haven't lost anything compared to what inspired me to learn KM, and repeating it a number of times is more important to me anyway.
The problem is solved, thank you so much @Nige_S!

"Not much", not "no".

Your repeat macro simulates a single, quick, key press -- there's no ability to "press and hold", so "Key Repeat" can't be used. So the only case I can think of where this will be a problem is when you want to repeat your Quick Macro either a set number of times (your macro) or "for as long as I hold they keys down".

Once you're at that stage you're really outside the "Quick Macro" use-case -- just write a "normal" macro and include all the options you need.