Create Pre-Filled KM Actions

I find this very handy when writing/debugging macros. I trigger each option via dedicated Stream Deck buttons, but not everyone has a Stream Deck, so I've set it up here to work via a prompt.

Here's what each of the prompt selections does:

  • Button: inserts a Press Button when Enabled action with the button name determined by a user prompt.
  • Text: inserts a Display Text action with the displayed text determined by a user prompt with display type options.
  • TriggerValue: inserts a Display Text action preset to display %TriggerValue%.
  • SystemClipboard: inserts a Display Text action preset to display %SystemClipboard%.
  • YES: inserts a Display Text action preset to display YES (useful when determining if a macro is successfully reaching a certain point of its run).
  • Variable: inserts a Display Text action set to display a variable. Before triggering this, ensure the text field containing the desired variable is currently selected.
  • Variable Prompt: as above, but in the form of a user prompt, which acts as a pause, giving you the option to either continue from that point or cancel the macro.

Create Pre-Filled Action.kmmacros (59 KB)

Macro screenshot

7 Likes

I would be very interested to know: Which method do you use for the call via Streamdeck? And do you have a special profile for KM or do you use it via a special folder?

I'm new to using Streamdeck and would love to know more if you have anything to share :smiley::+1:t2:

I use KMLink and make good use of the Parameter function (accessed in KM via the %TriggerValue% token), so that multiple buttons calling the same macro can do different things. I organise macros in Groups according to their app-specific availability rather than how they're called.

1 Like

Oh wow, thank you very much, I will try KMLink. I tried the Elgato Keyboard Maestro plugin, but gave up after I realised that the macro is bound to the button and can only be moved in an elaborate way... Thanks!

@cdthomer took the time to write this great post that you might find helpful.

2 Likes

I like this Neil! I have something similar for predefined actions, like a comment with a date stamp and the words “Follow up comment” for macros I need to come back to later on (and a corresponding smart group for macros with said comments).

Any reason you went with the prompt for user input instead of prompt with list? I’ve found the prompt with list is faster when I don’t need to select multiple options.

Yes, there's an excellent reason and it's definitely not because I was tired and didn't think of it. (I've updated it above :woozy_face:)

2 Likes

Yea I’m glad that “never” happens to me either. :sweat_smile:

2 Likes

This is neat. How do you figure out the XML code for the different actions?

I wanted to expand on your macros, but can't get my new choices to work. I tried to manually create the actions, then export it and copy-n-paste the XML back in, but it doesn't work.

I typed recognisable words into the various fields of an action I want I reproduce programmatically, then copied as XML and pasted into TextEdit.

I used these words as a visual reference for which value should go in which part of the code and I replaced them with variables.

Then, in order to paste this into a Set Variable action, you have to 'break' the XML by adding a random word somewhere it shouldn't be.

Copy and paste the XML, then delete the random word. This enables it to be pasted as text. If you don't do that, the XML will actually be pasted as actions.

Do yourself a favor and use a good plain-text editor like BBEdit when working with plain-text.

Eventually with TextEdit you'll accidentally monkey with RTF when you think you're working with plain text and fall down a rabbit hole – not to mention the fact that TE is feature-poor.

I keep the following on all of my macOS systems:

  • BBEdit
    • Coding
    • RegEx find/replace.
    • RegEx Playground (regex development).
    • Shell Script development.
    • Indescribable number of plain text transformations.
  • Eddie
    • Testing.
  • TextMate
    • Testing.
  • Visual Studio Code
    • JavaScript Development.
I specifically recommend BBEdit because…
  • Although BBEdit is a commercial product, the trial version reverts to a
    still very powerful and free (BBEdit-Lite) version after 30 days.
  • It is very Mac-like.
  • It has excellent support for RegEx.
  • It is very AppleScriptable.
  • It has a two versatile command line tools.
  • It has been in continuous development for over 25 years.
3 Likes

Hmm...

That's roughly what I've been doing, but I guess I must've been doing something wrong – because it's working now.

This is so fantastic! Thanks!

1 Like

This makes sense for StreamDeck since you want to press one button for each action you want to insert, but for keyboard "choose action", I would think KM's native Favorite Actions, or KMFAM might be a better choice? You just set up the action(s) the way you want them, and save them as a favorite action.

If you want to prompt for user input, you can use KMFAMs "Favorite Macro" feature, although I'll admit the documentation is probably lacking in this area.

Correct me if I'm wrong but I think they do slightly different things. For example, if you select "Variable", the specific variable in the currently selected action field will appear in the newly created display action below it. Very useful!

I guess that's what I get for not reading closely enough. Thanks for the clarification!

1 Like

No worries. I should really have provided a demo video for clarity.

CleanShot 2023-02-05 at 18.21.29

1 Like