Incremental paste adding to original text

I'm sure this is really basic and has been answered before, and apologies if so, but I'm just not sure what to search for here (only been using KM for a few days).

What I am trying to do is to copy something onto the clipboard, and then be able to paste it with "1" after it. Then paste again and it's "2", and so on. If I Copy something else, it resets the counter and does the same thing. eg.
Copy "apple"
Paste "apple2"
Paste again "apple3"

Copy "orange"
Paste "orange2"

And so on. I'm sure it's doable but everything I've tried has given me some kind of an error (and I'm sure whatever I've tried is probably way off the mark and massively convoluted anyway).

Thanks

Okay, you probably need two macros. The first one will look like this:

===============================================
And the second one will look like this:

===============================================

Are you able to type those macros yourself? It will probably help if you do it yourself.

The idea here is that whenever the clipboard changes, the first macro will set a global variable to "1". And then whenever you press the paste key, it will increase the global variable and then paste (by typing) the contents of the clipboard and then the global variable.

It works for me. If it doesn't work the way you expect it to work, you should explain what the issue is.

2 Likes

When I've done similar things in the past, I've used one macro with two triggers, then branch based on the %TriggerValue% token.

But that is a bit trickier to follow for someone new to Keyboard Maestro, so separate macros may be better.

-rob.

2 Likes

Ok yes! Thank you :slight_smile: works beautifully!! Messed up a bit along the way by having the second variable calculation to 1 as opposed to digitcounter+1 but I sorted it. Really really appreciated!

Thank you for this :slight_smile:

This looks really useful for a lot of stuff I'd quite like to do actually. I'm curious - the Variable names, they can be anything right? Like "Temp_counter" is just for ease of following your macro?

Yes, they can be anything. Generally, you should try to use local and instance variables, which vanish at the end of each run. (Local are only available in the macro they're created in, instance are available in that macro and any macros it calls.)

Globals can be used anywhere, but they're permanent. Lots of good info here in the Scope section:

https://wiki.keyboardmaestro.com/manual/Variables

I tend to use very few globals, and if I'm doing something with one I don't need, I give it a name that sorts it to the end of the list to make it easy to find and remove.

-rob.

1 Like

This is very cool; I didn't know you could do this; thanks for sharing!

I think in this example there may be a need for a delete past clipboard to get the proper results but I could be wrong.

Otherwise you get the case as in the Orange vs the Apple

image

For what it's worth, the %Variable%AnyNameVariable% is recommended versus %AnyNameVariable% and not to be confused with Tokens, which also are surrounded in % % percent signs. If they were surrounded by something else, that would have made it much clearer years ago, looking through macros, that they are something different, as in the calculations used above of %SystemClipboard% and %TriggerValue%, etc. Those are tokens and not random names of variables, which can also have spaces in their names. As Peter put it here on the forum, it is not the 1970s anymore, and we can have spaces.

https://wiki.keyboardmaestro.com/manual/Tokens?s[]=tokens

Hopefully that is useful since it has made it more difficult or me to always spot Tokens verus people's random Variable names.

Tokens Vs Variables Macro (v11.0.3)

Tokens Vs Variables Macro (v11.0.3)

2025-02-02 Tokens Vs Variables Macro (v11.0.3)

2025-02-02 Tokens Vs Variables.kmmacros (37 KB)

I am not a power user like so many here, and perhaps there is something I missed years ago about quickly being able to spot a token versus a variable. Of course, reading the whole macro, you will see when something is set to a variable, but as far as I know, unless you have all the tokens memorized, you can not just spot a token from a variable since they are both surrounded by percent signs.

In both @Airy and @griffman they used %Variable%TheVariableNameNext% to thankfully make it very clear and easy to follow though it is not required. Unfortunately (or perhaps fortunatly), when you press command+control+v and search for a variable to insert into your macro, Keyboard Maestro doesn't add that and just does the variable name. I am guessing perhaps users that do this all the time have a macro for writing this out quicker.

Insert a Variable Macro (v11.0.3)

Insert a Variable.kmmacros (31 KB)

1 Like

Notice that I use Insert Text by Typing and your your macro uses Insert Text by Pasting. When you paste, that text goes onto the clipboard (that's how Paste works). But if you insert by typing, it just types the text, so the clipboard is unchanged.

So yes, if you want to insert with paste, you need to delete the clipboard after the paste.

Yea, and it's a very simple macro:

It looks worse than it is, because there's a %|% in there, which means "position the cursor here." But then because that's a token, and tokens are processed, there are extra % signs to make it work…and it always confuses me to try to explain double-quoting of tokens, so I won't even try. I just know that what I have works—I found it somewhere here in the forums, I believe.

I have it assigned to a typed string trigger of vv, because I've never needed to type the word savvy in the Keyboard Maestro Editor :). When I type vv, I get %Variable%%, and the cursor is between the last two % signs, ready for me to type the variable name.

-rob.

1 Like

Good idea. I may try that. For ten years I've been typing "%Variable%%" (I have never used typed string triggers. Yet I probably have manually typed "%Variable%%" 20 to 50 times per day.) I presume you implemented that macro to be enabled only when the KM Editor is frontmost.

Although now that you've got me thinking about it, maybe I should use the following additional shortcuts instead: (these are things that I manually type a lot)

  • %v for %Variable%%
  • %c for %Calculation%%
  • %d for %Dictionary[A,B]%
  • %tv for %TriggerValue% <-- I would use "tv" here to make it compatible with the next section

And here are some additional items that I occasionally type that I will probably also add:

  • %a for %ActionResult%
  • %f for %FrontWindowFrame%
  • %l for %LineFeed%
  • %n for %NumberDate%
  • %p for %PromptButton%
  • %r for %Return%
  • %tb for %TriggerBase%
  • %tr for %Trigger%

Perhaps some people use other tokens with a different frequency distribution than I do, so variations to these lists could be appropriate. For example, some people might use the Application tokens a lot, and so they might add these to their list:

  • %AP for %ApplicationPath%%
  • %AV for %ApplicationVersion%%
  • %AL for %ApplicationLongVersion%%
  • %AB for %ApplicationBundleID%%
  • %AN for %ApplicationName%% <-- which is the same meaning as %Application%%
  • %LA for %LastApplication%% <-- curiously this token ends with the letters: Application
2 Likes

I totally missed that, I figured there was something like that. I also didn't realize that it had to go to the system clipboard to paste. Thought perhaps there was some background location Keyboard Maestro could pull from to paste but maybe not, so that was good to learn.

I figured mine was overly complicated and I was hoping there was something like that to move your cursor to a location. I do that all the time with TextExpander but hadn't yet learned that in Keyboard Maestro. So many things I am learning from this thread.

Haha but what about bevvied? :stuck_out_tongue_winking_eye:

Great list, I think I will implment these as well, thank you for sharing!

That's a savvy comment.

2 Likes

I took this one more step to allow for a choice among global, local, and instance variables. So, "qvg" for global, "qvi" for instance, and "qvl" for local.
PS Delete the "display text" action - that was just for testing

Quick var Macro (v11.0.3)

Quick var.kmmacros (4.7 KB)

1 Like