How to use variable to paste 4 Clibboards” Macro?

Hi all,

Here I'm using a very simple but handy macro for saving (up to) 4 clipboards from a text which I want to keep.

I'm sure the macro could be simplified by introducing a variable of some sort, but how to do that?

/
Any assistance would be greatly appreciated!

With best regards,
Omar KN

Keyboard Maestro 8.1.1 “Paste 4 Clbs” Macro

Paste 4 Clbs.kmmacros (9.1 KB)

KM variables can only contain plain text (including numbers). When it comes to styled text and images you need Named Clipboards. Think of Named Clipboards as “Variables for styled text and images”.

Thus, since apparently all of your clipboards are about styled text, you made the right choice, I think.

Maybe the styling could be applied afterwards?

If plain text how would one employ a variable, one for each Clipboard?


This may appear as an ‘over-kill’, but I thought to use it to better understand how to use variables, which I last time encountered at school - in algebra and geometry :slight_smile:

/
with best regards,
Omar KN
Stockholm, Sweden

Yes, this can be easily done. IMO, it is always better to use KM Variables rather than KM Named Clipboards whenever possible.

Here's an example.

Example Results

image

MACRO:   Use Variables with Styled System Clipboard


#### DOWNLOAD:
<a class="attachment" href="/uploads/default/original/3X/6/7/674b1a1d8e0ce00421346f3f9f5a5f3be3c7439c.kmmacros">Use Variables with Styled System Clipboard.kmmacros</a> (7.0 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**

---



![image|505x1813](upload://z2fh60JSZmnzB6cGhZSZ9wbSwpm.jpg)

Questions?

Yes one questions, please:

Well, as a start one would need to select/ copy some text…

How does KM macro receive the input of a text snippet if not from a clipboard?!

(OK it says: from the System clipboard… .)

/
with best regards,
Omar KN
Stockholm, Sweden

Generally, for selected text, to get it in to Keyboard Maestro, copying it to the System Clipboard is the only way.

With some applications, you may be able to use AppleScript access, or Accessibility APIs, and with web pages, there are other solutions, but in general, via the clipboard is the only solution.

Yes I get those same Example Results.

However I don't know how to copy any text. f ex 'Clipboard 1', Clipboard 2, etc - 4
so that it is received by the variables 'SerialVar_1!…

Just insert these two Actions wherever you want to copy text that is selected in the FrontMost window into a KM Variable:

image

Of course, you can use any KM Variable you want.

deleted

The question is still: how (if at all) can variables simplify the (original) “Paste 4 Clipboards” Macro.

The purpose of the macro was to get several snippets from the same webpage.

Up to now it was done with different Serial Clipboards1, ~2, … ( ⌃ C 1, ⌃ C 2, ⌃ C 3… ) as in our original example.
(see original at top)

But I connot reproduce this with a KM macro, which uses variables.

(See an example below, which doesn’t really use a variable).

.

Keyboard Maestro 8.1.1 “Use VariablesB with Styled Serial Clipboard” Macro

Use VariablesB with Styled Serial Clipboard.kmmacros (5.0 KB)

/
Any assistance would be greatly appreciated!

With best regards,
Omar KN

OK, let's say you want to copy 4 different sections (non-contiguous) on a web page.
I've done a simple example. Your KM Clipboard History will look like this:

image

So now, let's put each copy into a KM Variable:
The Clipboards in the Clipboard History are numbered starting with 0, so the last copy you made, which is always the first Clipboard, will be Clipboard #0.

You can use this KM Token to reference it:
%PastClipboard%0%

The value of this Clipboard (#0) is:
"Copy #4"

So here is how we need to set KM Variables in the order that you made the original copies, which will be the inverse order stored on the Clipboard History:

image

To verify, here's the Display Window showing the results:

image

Now that you have the data you copied from the Web Page into KM variables, you can output them in any order, and apply a style, if you wish, before you do so. So now, I set the System Clipboard to Local__CBItem_1, apply style, the display the clipboard.

image

and here is the result:

image

Of course, instead of displaying the clipboard, you could paste into the rich text app of your choice, like TextEdit:

image

and here is the result:

image

So here is the complete macro.
Remember, you MUST first copy (from anywhere) FOUR times, then trigger this macro.

MACRO:   Put Last N Items on Clipboard Into KM Variables [Example]


#### DOWNLOAD:
<a class="attachment" href="/uploads/default/original/3X/a/6/a6d6b24cbe474af64d139914732548424d853ce8.kmmacros">Put Last N Items on Clipboard Into KM Variables [Example].kmmacros</a> (6.8 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**

---

![image|514x1996](upload://rPPCpskLSkwdFRPFkQXd6aIFVor.jpg)

---

Questions?
2 Likes

:+1:
Thanks JMichael, now this was (at least for me) a nice example of variable usage!

3 minor points:

1.)
under: How to Use, one could suggest from where those clipboards could stem from:

  1. Copy (from anywhere) 4 times
    [for ex. with Serial Clipboards1, ~2, … ( ⌃ C 1, ⌃ C 2, ⌃ C 3, ⌃ C 4 )]
  2. Trigger this macro

2.)
then: in Set System Clipboard to Text (plain text)
all four variables should be listed, of course - I think you just wanted to test me :wink:

so for example:

%Variable%Local_CBItem_1%

%Variable%Local_CBItem_2%

%Variable%Local_CBItem_3%

%Variable%Local_CBItem_4%
.-.


3.)
Also in my usage, after ’Apply Style to System Clipboard’

I directly add the ’Paste’ action. That way I can paste it anywhere.

.

The macro is great, thank you! :yum:

/ Omar K Neusser
(text worker - part time)

I'm glad you found it helpful.
If one of the above posts solves your problem/question as originally stated, please check the "Solved" checkbox (click for details) at the bottom of that post.

Otherwise, please post your remaining questions/issues about this problem.
If you have other questions, please start a new topic.