Howdy folks, I thought I would share a simple macro that has saved my bacon a few times.
I like to use typed strings for certain kinds of macros, but as everybody knows, if you want Keyboard Maestro to delete that string, it can cause issues depending on what app you're in. God forbid you trigger a macro like this while you're editing a macro because you could end up deleting a bunch of actions haha.
So what I do is unselect the option to delete the typed string in whatever macro that uses them. Then, as the first action, I place an "Execute a macro" action using the
%TriggerValue% token as a supplied parameter. This parameter is passed to this macro, which counts the number of characters in the parameter and sets a variable to be used to delete those characters.
For instance, if my typed string is
-test, then the
%TriggerValue% will pass that string to this macro, which will count 5 characters and set the variable to 5. That variable will then simulate the delete key 5 times to get rid of the string.
It's not fancy, but it works well for me and maybe will help others too.
EDIT: Updated to use RegEx to match front application instead of a list of applications. Thanks to @tiffle for the tip!
CURRENT VERSION: 2.0.0 (Saturday, March 19, 2022)
v2.0.0. Saturday, March 19, 2022
Added an if command to prevent the macro from executing unless you are in a text field.
This will prevent accidental unwanted deletion of possibly important information (like the 5 notes I just deleted ).
VERSION HISTORY (click to expand/collapse)
Version 1.1 uses the character count of the typed string trigger to set the variable used for deleting the characters.
This means you no longer have to specify a number in the "Execute a macro" action, but rather can simply pass the %TriggerValue% token as a parameter.
This makes it a lot easier to use as you can save it as a favorite (with KM10) with the parameter already supplied.
12)Delete typed string trigger text (subroutine).kmmacros (12 KB)