Typed string trigger using regex - can I use "a word followed by a space" to trigger

I have a macro that I would like to trigger if #\w+\b (regex version) is typed. Meaning that the macro should trigger if (# followed by a word followed by a space) is typed.

There are a few threads here that talk about this but I am not able to understand how starting the regex with a \b can help in this case. Tried everything from those threads of course.

Why: Trying to select a hashtag using (prompt from list) action to select from my existing hashtags.

Thank you.

The issue is not the \b. The issue is that KM does NOT support use of Typed String trigger in one of its Prompts.

BTW, you do not need a \b (word boundary) at either the beginning or end of your match pattern since you are using \w+, which restricts the match to word characters.

Thanks @JMichaelTX for your reply.

What I meant to say is that I would like to type "#r " or "#run " in a editor to trigger the macro. So "# " should trigger the macro.

Also, while I have figured out how to copy the partial trigger text into "Prompt with list", would ideally like to the cursor to move to right after the copied text. That would allow seamless typing of the tag and selecting one from the list.

2020-05-14 at 19.20.16
Macro attached here: Tag selection macro.kmmacros (4.1 KB)

Credit: This macro based on a macro by @matti here.

That trigger would trigger as soon as you type β€œ#r” because at that point there is a word break at the end of the text.

If you mean a space, include a space in the trigger β€œ#\w+ ”.

β€œ# ” will not trigger the macro because β€œ+” means β€œone or more”. If you want to allow zero or more word characters preceded by β€œ#” and followed by space, then use β€œ#\w* ”.

When thinking about Typed String triggers, remember a couple points:

  • Keyboard Maestro cannot see in to the future, so it only knows the characters you have typed up to a given instant - it has no idea what you might type next.
  • Keyboard Maestro looks at what you have typed and matches that against the trigger based on its configuration.

So a regex can have $ or \b at the end of it, since the string being matched comes to an end after the last character you have typed, regardless of what you might type next, but having such a character in your regex is unlikely to be helpful.

1 Like

"#\w+ " works as a trigger. Thank you. I think I understand better also how regex works in typed string triggers.

one followup question - is there a way to have the "prompt with list" dialog begin with the cursor being right after the "Default"?

This would be with cursor right after the Default text - 2020-05-15 at 09.56.21

This is what currently happens - 2020-05-15 at 09.57.31

And finally, thank you for pulling together such a useful software!

Generally it is better to ask different questions on new topics, otherwise other people cannot find the answers. But no, there is no way to do that - just press the right arrow if that is what you want. Technically, you could use an Execute a Macro action, configured to be asynchronous, which typed the right arrow after a short delay, but I would not recommend it.