Set Variable to Selection Without Involving Clipboard

One method would be to make use of past Clipboards - which Keyboard Maestro can easily do. So, copy the two items you want then Paste in the Current Clipboard and then the Clipboard before that.
https://wiki.keyboardmaestro.com/action/Set_Clipboard_to_Past_Clipboard

Unfortunately not all apps support AppleScript, and apps that do support it have their own way of doing things.

Certain things are standardized, but only if Apple's standard AppleScript dictionary is included with the app ā€“ and devs can override things in that.

There is no such thing, although in my opinion there should be.

You can copy more than one item and then manipulate the past/present clipboards as @JMichaelTX and @Zabobon have suggested.

You can copy to the clipboard and then save that clipboard to a variable or to a saved clipboard ā€“ then you can manipulate those.

Or you could do something like this (with Google Chrome):

Chrome Selection + URL to Variables then Clipboard.kmmacros (3.3 KB)

-Chris

Hi Chris,
Thanks for updated Macro, I have managed to add Chrome title to it as well
Just out of interest, the macro Feb12
had "window.getSelection()+'';"
where as the the most recent one has window.getSelection().toString()
The output for both is similar to naked eye, are they different ?
Also do we have a similar javascript to paste a variable in chrome
(as get selection from window.getSelection().toString() in Tab1, then emplace it in Tab2
I have used this as textexpander snippet, and works brilliantly as a work around
Thank you for ur help

Hey @lucky,

The code is different ā€“ the result should be the same.

Using +'' is sort of a hackish way to turn an object to a string in JavaScript, whereas .toString() is now canonical.

(I'm not sure when .toString() became available and only noticed it sometime in the last year.)

Google Chrome's AppleScript dictionary does support:

paste selection reference

The reference being the tab you want to paste into.

This can be handy, but it's limited to the active selection in that tab.

-Chris