[Solved] How to Use Keyboard Maestro Variables as Arguments in Actions

Hey everyone!

So I recently decided to try Keyboard Maestro and to be fair, I'm trying to do something fairly complex, but also it kind of sucks that it won't do it.

Basically, the limitation is that KM doesn't allow you to input variables as arguments into a lot of it's different actions. In fact, most of them won't take a variable, from what I can tell. For example, the repeat action. I can't dynamically input a variable (for example, the repeat count) based on a pre-calculation of a prior action. Or let's say that I want the mouse to be moved X distance based on a variable, I can't do that. Currently, you can only provide it with a static pre-determined number.

Anyway, this would be a game changer, but I'm guessing it would require a rewrite of sorts. Does anyone have any ideas or suggestions or is Keyboard Maestro simply not up to the task? Of course, I've just started using it, so I may be overlooking something.

I tried looking into Hammerspoon, but the documentation is dreadful for a beginner.

Most KM actions can take variable even repeat action.

Besides, some actions might require this format: %Variable%varName% as input
https://wiki.keyboardmaestro.com/manual/Variables

3 Likes

Thank you! How did you do that Repeat Actions Local_executeCount Times??? I don't see any options for it.

Oh right, so you literally just input the variable. I guess it's a UI thing, but thank you! This has given me a lot of confidence :slight_smile:

Hi @dottjt and welcome to the friendliest and most useful Forum on the Planet (in my opinion).

I hope you don't mind but I changed the title of your question from "Huge limitation with Keyboard Maestro (won't allow variables to be used as arguments in actions)" to "How to use Keyboard Maestro Variables as Arguments in Actions" as in fact this is not a huge limitation of Keyboard Maestro as Variables can be used in the way you wanted.

3 Likes

Thanks for that, no worries. I think I just had a really frustrating day and that was my way of expressing it, but glad to be on board :slight_smile:

1 Like

Likewise, no worries :grinning:

The titles of these questions often get changed/simplified to help others in the future who are looking to solve a similar question. If the title says the question can't be answered it might put them off at the first hurdle.

Debugging complex Macros often comes down to getting the syntax right when including Variables within Actions. So, as you construct your Macro and find bits don't work as you intend - please keep asking for help here (if possible, including screenshots and the actual Macro). Everyone is happy to help. In my case I've received amazing help here and it feels great to be able to give back a bit when I can.

1 Like

Pretty much anywhere in the KM UI that you can enter numeric data, you can also enter KM Functions and Variable Names (without the % which makes it a token).

See

Just a suggestion, but I think a lot of the issues/frustration with KM I've had has simply come down to the UI. It's just so inconsistent, that it isn't self-documenting. Like, giving hints in terms of what values to input, as well as how it's designed in general.

I think the approach I've noticed to combat this is with further documentation, but it's much less accessible than having the UI be self-documenting. But yeah, I'm sure this will improve over time.

I think it does do this - but maybe not in the way you expect.

https://wiki.keyboardmaestro.com/Getting_Help_in_the_Keyboard_Maestro_app?s[]=help

Also, for entering Tokens and Variables - if you enter something invalid it is shown in red until it is acceptable:

image

And Tokens/Variables etc can be entered without having to type them using the Edit Menu

I recently had to get to grips with Apple's Logic Pro App and had to stop every couple of minutes or so to work out how to do something or make a setting that I thought should be simple - but just wouldn't work the way I thought it should. Logic has all sorts of inbuilt help including hints that appear at the cursor (I'm sure Apple must have a much larger budget for Logic compared to Keyboard Maestro, which is by an individual developer) - but I still found the quickest way to find the answer was just to type in my problem in Google...

Maybe take a breath and try some easy things first. I have been using Keyboard Maestro for several years now to automate and streamline so many things on the Mac. For me now, a Mac without Keyboard Maestro installed is not really a Mac...

2 Likes