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.
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.
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 “
# ” 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 “
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
\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.
"#\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 -
This is what currently happens -
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.