Repeat next macro N times (emacs argument)

Is it possible to make a macro that, for example, repeats the next macro you run by a keyboard shortcut twice? I want to implement an Emacs argument for my keyboard editing shortcuts. Ideally, it would work the following way:

  • I press control+u and a digit N (I'm OK with defining 8 macros manually for the purpose for digits 2-9), preferably without having to press enter in an input window
  • I run any other macro by keyboard shortcut
  • that macro is run N times in total

I understand this is an extremely tall order, so I would be also interested in more basic ways to set up ways to move or kill 2 or 3 words and such.

You want your macro to intercept ANY keyboard shortcut for ANY other macro? I would say no. No macro can intercept hotkeys for another macro.

But you did state your problem, and I want to think about your problem. There may be a way to solve your problem.

Hmm, can I assume that the macros you want to run multiple times do NOT use a parameter?

They do not. I have two dozen macros that implement Emacs text editing shortcuts — macOS has some of them out of the box but those versions do not work in a Cyrillic keyboard layout or in MS Office apps. For the most part they just perform either a single action:
option+f to option+right arrow
or a short sequence of actions:
option+t selects word to the left, cuts it to a private clipboard, moves cursor one word left, pastes the word to transpose words.
I am extremely attached to these shortcuts and being able to dispose of Karabiner Elements and its gigantic JSON which was required to set up exceptions etc was a great benefit of starting to use Keyboard Maestro.

I already maintain two sets of these shortcuts (MS Office often needs adjustments in more complex motions), so I would not mind making a third set which accepts an argument. I've attached the macro sets that I want to be repeatable — I do not need to apply this to arbitrary macros.
Emacs (MS Office) and Other Macros.kmmacros (194.8 KB)

That's not exactly what I was thinking. What I was thinking was that you could modify each of your existing macros to look like this:

And then we would have to find a way to solve the other half of your problem, which is to specify a number and choose one of those macro. I think I can probably solve that too.

Easiest way is to set up a "number catcher" macro, enabled by your ⌃U-triggered macro, that appends any number typed to a global variable or uses ESC to cancel and reset. The problem is telling that macro when to stop capturing... You could build that into your other macros.

Here's a demo Group:

Emacing Macros.kmmacros (15.2 KB)

The meat is the "Emacing - Number Catcher" macro:

For the full emacs experience you could instead use the catcher to capture letters to pick which macro to then run:

Emacing v2 Macros.kmmacros (14.6 KB)

Hopefully the above will give you some ideas!