Typing trigger not firing

I've been using a macro for a few days now. The trigger is ...

  • press CTRL
  • type one or more digits
  • type a non-digit character

The macro itself deletes what I typed, then pastes "that many" of the non-digit character. For example, when I type CTRL 4 0 -, it deletes the 40- and then pastes 40 "-" characters. This image shows the macro itself.


The problem is, half the time the macro doesn't trigger, but then when I try it again it works. I can't tell if there's some kind of timeout, i.e. if I'm supposed to type the whole sequence more quickly than I have been, or if the keyboard itself is somehow "timing out" and KM only recognizes the CTRL keystroke if it's been less than a certain time since the previous keystroke.

It feels like I'm missing something really obvious here, but I'm not seeing it.

Any ideas?

CTRL is doing nothing here -- it's ignored if you type it without any other key held down (unless you've another "USB Key"-triggered macro that uses it) and your macro doesn't use it anyway -- the ^ at the start of the regex is the "start of string" anchor, not the Control key symbol.

Perhaps you are sometimes holding down the Control key when you type the digit? No digit, no macro...

I think the issue is the use of the Control key in the regexβ€”in my testing here, it seemed very flakey. Something like this will work 100% of the time:


Type two semicolons (or any other character combo you're unlikely to normally type) and then you can do the rest as you had it. However, I'd probably write it this way, as it's much simpler and still very fast:

Download Macro(s): Insert N characters.kmmacros (2.8 KB)

Macro screenshot

Macro notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System information
  • macOS 14.5
  • Keyboard Maestro v11.0.3

You don't need the temporary copy to paste the variable; just paste it after you create it.


That's what I thought at first, too, but KM is pretty smart and does insert the Control key symbol, which is different than the front of string carat. Here's "look for Control at start of string" as a trigger:

Note the different characters. However, none of the negates what you said: I still don't think Control is doing anything here. But KM does try to treat it differently than the start-of-line carat.


Your post crossed my edit (after I'd taken a closer squint at the picture...).

And I'm going to take the rest of it back, too. The βŒƒ key does work as an "independant" key in a typed string trigger -- which totally upends my understanding of how they work!

It doesn't fire if you've still got the βŒƒ key down when the digit key is pressed, though -- so ~10% of my post was right...

1 Like

My first instinct was to use F15 as the "start" key, however one of the machines I use all the time is a MacBook Air, which doesn't have an F15 key. I wanted something that either I was guaranteed to never need to type in front of a digit (which ruled out my first tought, =) or that wouldn't actually insert any characters by itself. I didn't know that KM would even allow CTRL like that until my hand "fell" on to the key and I saw it add the βŒƒ in the input control. (I also tried βŒ₯ as the starter, that worked at the time as well, maybe I'll try changing to that and see if it works more consistently.)

Also, I have been careful to release βŒƒ before starting to type the first digit, that isn't the problem.

And did I understand correctly, the "copy system clipboard to hold" and "copy hold to system clipboard" steps aren't needed? Does the "Insert text ... by pasting" step take care of this automatically and I just missed that in the documentation? I'm going to test that as well ...

Yes, insert text by pasting does just that: It pastes the item by putting it on the clipboard. Many times you'll want to follow it with a Delete Current Clipboard to get that stuff off, if you're doing other things with the clipboard and expecting a certain value to be there.


Think of it more as a whole string to be detected, rather than a "first character indicator". You'll see that @griffman generally starts his typed string triggers with a ;; while I wrap mine with a starting and ending ; (so my version of your trigger is ;\d+\D;). Both work as "start points" for KM to monitor what follows for a match because it's very rare in normal use to type either a double semi-colon or one without a following space.

It helps if you're consistent, but what you choose depends on what you do. I've seen a lot of people use ,, -- but I mess around with comma-delimited text too much for that to work for me.

Using modifiers in typed string triggers is a new addition in KM v11 -- I really need to catch up with the new goodness!

That the macro sometimes works and sometimes doesn't is the odd thing here. You're probably not pausing your typing for the few seconds needed for the trigger to time out -- do you, perhaps, have one or more frequently-firing "background" macros?

1 Like

At the moment I only have two - this "repeater" macro, and one that watches for me to type a ticket number of the form [ABC-123], which immediately adds (https://hostname/ticket/ABC-123) (to automatically make a link in a Markdown document, I use A LOT of Markdown).

FWIW, using βŒ₯ as the "start key" instead of βŒƒ seems to be helping - I haven't had it not work yet, but it's only been about 45 minutes. I guess we'll see what happens for the rest of the day ...

Sorry, I didn't ask the question clearly. Do you have any "periodic" or other automatically-triggered macros that might fire while you are typing? A macro executing while you are typing your trigger string will cancel the sequence and your macro won't run.

No ... and until you mentioned it just now, I didn't even know that KM could do that.

I don't think I have any need for this, but I am going to go read about it when I get a chance. Thanks for mentioning it.