Utilizing the REPEAT action using PastClipboard

Is there any way of feeding the “Execute the following actions ___ times” of the REPEAT action with the contents (which would be a number) of a PastClipboard?
I have tried several ways, but always end up with the “%PastClipboard%5%” showing up in red as well as a red
"—> invalid."
I am building a Send Mail Message macro utilizing several numbers and words from database records that are copied to the clipboard by the database and then pasted by KM into my macro via PastClipboard. The number of these emails vary. However, that number does appear in the database and is also copied to the clipboard. I just can’t seem to get that copied number to feed itself into the REPEAT action.
Any help or suggestions would be appreciated.
I’m kinda new at this, so please go easy on me!

Thanks,
Rich

Firstly, the ___ in “Repeat actions ___ times” is a numeric calculation field. It is important to understand the difference between calculation and text fields in Keyboard Maestro, so read the Text Fields wiki article.

There is no count of past clipboards (well, there might be a function for that, but it wouldn’t help even if there was). What you need to do is use the value you copied that has the number of clipboards. Do you know which clipboard that is stored in (because it it is not at a fixed location), then you won’t know where to find it without know it which is a problem).

How are you behaving with the different numbers of clipboards? Because if you just want to paste each of them, an alternative is something like this:

  • Copy a known value (eg “KM END KM”) using Set Clipboard to Text
  • Copy each of your items.
  • While clipboard is not “KM END KM”
    • Paste Clipboard
    • Delete Current Clipboard

Peter:

Thanks for your reply!
Perhaps I didn’t explain my problem well enough, or I am not understanding your answer.
What I want to do is to take a number that has been copied to the system clipboard, and then get it into the "“Execute the following actions ___ times” of the REPEAT action.
That number could be any number, but it is NOT the number of the past clipboard

Example :

-After copying from a database, the clipboard contains the number 482.
-The clipboard that holds it would be “%PastClipboard%5%”
-I am trying to get the number 482 into the “Execute the following actions ___ times” of the REPEAT action.

BTW, I have accomplished this by utilizing the “Prompt for User Input” action. Under the “Variables and Default Values:” Entering a variables name “COUNT” followed by the “%PastClipboard%5%” Then using the “COUNT” in the in the “Execute the following actions ___ times” of the REPEAT action.
-But I would prefer the macro not require any user input.

Thanks,
Rich

Hi Rich,

If you can be sure that %PastClipboard%5% will always contain the number of times you want the actions to repeat, you can skip the prompt step and set the COUNT variable directly using the "Set Variable to Text" action:

That said, I personally wouldn't be comfortable with relying on past clipboard numbers like this since their contents can fluctuate so easily, so I would suggest making a new macro specifically for the purpose of setting the COUNT variable to the current system clipboard and copying the number used for the repeat action using that macro:

You could even use this technique to set variables for all the data you want the macro to process, which would again be much more reliable then relying on past clipboards. One easy way to do it would be to make several macros just like this, one for each kind of data you want to copy/process, and assign them all the same hotkey. When this hotkey is pressed, KM will display a conflict palette showing every activated macro assigned to that hotkey, making it easy to select which variable you want the current selection set to without needing to set a different hotkey for each one.

Finally, if you go this route, the last suggestion I would make is to display the contents of all of your variables before the Send Mail Message macro is run as a way of confirming that everything is set the way you want. You can do this fairly easily with your existing Prompt for User Input Action by using the variables in the prompt itself, like this:


(unfortunately Prompt for User Input only has room to show two lines of text, but you can still enter more, as evidenced by the "Data2" line. And yes, I know you said you would prefer this macro not require any user input, but since this version doesn't require you to input any data, but is only used to verify the data that's already been set, I thought it was a worthwhile suggestion, especially as this verification step isn't required to make a macro setup like this work)

Anyway, I hope that all made sense. Feel free to post again with any follow-up questions you may have!

1 Like