Help with Macro Using Clipboard

Hi guys anybody can help me to build a simple macro to copy and paste? i certainly cannot make it possible :frowning:

This is what i wanna do. i got 4 lines that i want copy 1 by 1 and when i press a combination of keys make the program paste them with a tab Key between them
Form example

Name (copy)
Address (copy)
Postal Code (copy)
Number (copy)

and when i press the combination keys

Name [ tab key ] Address [ tab key ] Postal Code [ tab key ] Number [ tab key ]

Please i hope u guys can help me

Here's something I think will work. It assumes you've already copied the Name, Address, Postal Code, and Number, in that order.

Paste Name, Address, Postal Code, Number.kmmacros (5.8 KB)

I'm sure there's a more elegant way to do this, but this should work. Just assign it a hotkey.

By the way, you can think of the action "Delete Past Clipboard 0" as meaning "Delete the current clipboard value, then set the clipboard to the previous clipboard value."

If you activate the Clipboard History Switcher, you can actually watch it work in real time, if you care.

1 Like

Wow i donā€™t know how to say thank you, seriously you really helped me out

Thx

Glad to help!

Let me know if you need more help.

There many ways to "skin a cat" using Keyboard Maestro. :smile:
@DanThomas has given you a very good one.
Here is an alternate approach.

###Are you pasting into a web form?

If so, then you might consider this, which eliminates any issues with UI navigation (like if the order of the fields on the page changes).

  1. Manual Steps (but could be automated if I knew more about your workflow)
  2. Select and copy the lines manually (could be automated)
  3. Go to the web page, and open the web form
  4. Trigger the macro
    .
  5. Macro does this
  6. Search Clipboard and set variables to use in form later
    * Search for Regular Expression: (.+)\n(.+)\n(.+)\n(.+)
    * Set KM variables for each capture group (each line)
  7. Set the web form fields using these variables

You will need to enter the "Set Field" in each of the "Set Google Chrome Field" Actions.
The easiest way to do this is open the web form, and then go to the KM macro, and click on the "Google Chrome" dropdown to see a list of form field on the web page.

If you are using a web form and would like more help, please provide more details of your complete workflow, including which apps and browser you are using.

It makes a difference whether the ā€œTab keyā€ is intended to switch between fields or as a tab character in a text document.

In the latter case, you can simply do something like this:

Insert Text by Pasting: %PastClipboard%3%%Tab%%PastClipboard%2%%Tab%%PastClipboard%1%%Tab%%PastClipboard%0%

If the Tab character is to switch fields, then it must be typed individually, not pasted altogether. You could do the same as above with Insert Text by Typing. Depending on the size of the text, that may be fine.

Otherwise a solution like @DanThomas posted will be necessary, although if you are using all Insert Text by Typing (like Dan does), then there is no need to read them in to variables first, you can just use the %PastClipboard%1% tokens to extract each one. If you are Insert Text by Pasting, then since the clipboard positions move around, it is necessary to read them out as shown and then paste each in turn.

And @JMichaelTXā€™s solution is the direction you want if it is a well behaved web page.

Context makes all the difference, so itā€™s good to always be clear about what you want to be doing.

2 Likes

Hi @JMichaelTX actually im using a webworm and i did what you told me but when i trigger the macro it show me this

Could you please tell me what to do :frowning:

Please post exactly what is on the clipboard in a script block so all characters will be retained. A script block is like this:

paste your clipboard here

There are 3 backticks on a line before and after the text.

It would also be very helpful if you could upload your macro.
See How to Post/Upload Your Macro to the Forum

Vianey VillaseƱor
Thx @JMichaelTX I actually figured it out how to make it work but theres also 1 thing that i don't understand, I have this data

Vianey VillaseƱor
Aquiles Serdan 107
Col La Merced
50080

when I trigger a macro like @peternlewis said, using this config

Insert Text by Pasting: %PastClipboard%3%%Tab%%PastClipboard%2%%Tab%%PastClipboard%1%%Tab%%PastClipboard%0%

I get the this result
Vianey VillaseƱor Aquiles Serdan 107 Col La Merced 50080

As you see it actually reads and pastes the lasts clipboards just fine with intermediate Tab Keys

But when i try to do it separately simulating tab Keys like this


ļæ¼
I get This Result

Vianey VillaseƱor Col La Merced Vianey VillaseƱor Vianey VillaseƱor

As you see it actually repeats the first line twice and skips some data and i don't know why :frowning:

Everytime you execute a "Insert Text by Pasting", the Clipboard history is changed, with the current Clipboard being set to whatever you pasted.

If it were me, I'd set a unique KM Variable after every time I did a COPY, so you would end up with a set of Variables like this:

Contact_Name
Contact_Address
Contact_City
Contact_PostalCode

I would then use those variables to paste into your document.

1 Like