Simple problem converting numerical string on clipboard to number for repetition

Apparently despite all my reading and frequent questions I still can’t sort out numeric versus text fields and tokens vs clipboards vs. variables. I keep coming up with questions about them. Here’s my latest

I have filtered the current clipboard to get the number of characters it contains. (At first I didn’t know where that number went, but since there was no place else in sight I guessed successfully that it was the clipboard itself.)

I then want to repeat an action the number of times represented by the string in the clipboard. For instance, if the clipboard contains “8” I want to execute an action 8 times.

I can’t figure out how to convert the string on the clipboard to a numeric value. I don’t know whether I first need to set a variable to the contents of the clipboard, whether to use a calculation, whether I’m supposed to use a token, whether I can just use the clipboard, or what. I thought there might a function that converted a string representation into a number like in programming language, but Ii know I thinking too hard.

What simple thing am I missing which is going to embarrass me?

Here's the trick about numeric variables:

  1. You can only use them in Calculation fields. These are fields that expect numbers.
  2. In a calculation field, you reference a variable by its name only - no %Variable% stuff.
  3. In just about any numeric field, even if the edit box looks too small, you can use a variable. When you start typing a variable name, the edit box will expand, or move, or something.

Am I imagining things or are the macro steps shown in your recent posts magnified less than normal? The fonts seem small, but big enough.

One thing odd about the Repetition numeric field is that it doesn’t follow the FAQs point about numeric fields normally having up/down arrows.

1 Like

It's because I left my window wide, and there's only so much width it will show. Here:

Thanks. So it turns out that embarrassing thing about my failure to find the solution is that I did find the solution — exactly like yours — it just isn’t working for some reason. Have to look more closely.

You can use the Clipboard switcher to verify what’s on the clipboard, and you can use Keyboard Maestro Preferences -> Variables to monitor what’s in your variables. Sometimes that helps debug things.

Yes it does:

The arrows are removed after expansion of the field.

Amusingly, today I just finished adding a function CHARACTERS() so you can do this:

2 Likes