How to Get Values of %SystemClipboard% and %PastClipboard%1% in an AppleScript?

I know how to use the system clipboard in AppleScript, but I need current and previous one simultaneously. I know that KM collects all these current and previous values somewhere, but how to get them via AppleScript?

Very easy, using KM tokens:

tell application "Keyboard Maestro Engine"
  set kmCB1 to process tokens "%PastClipboard%1%"
  set kmSysCB to process tokens "%PastClipboard%0%" -- or %SystemClipboard%
  set mergeCB to process tokens "%SystemClipboard%%Return%%PastClipboard%1%"
end tell

Thank you very much!
It works fine.

Keep this script in return (if you find it useful, like I do):

tell application "Keyboard Maestro Engine"
	set theTitle to process tokens "%PastClipboard%1%"
	set theURL to process tokens "%PastClipboard%0%"
end tell

set theHTML to "<font face=\"Helvetica Neue\" font size=4><a href=" & theURL & ">" & theTitle & "</a></font>"

do shell script "echo " & quoted form of theHTML & " | textutil -inputencoding UTF-8 -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf"

It turns the text and the URL (consequentially copied - make a macro for it) to the RTF link, which you may then paste to Omni Outliner e.g. or any other RTF editor like Word or so, not wasting the time on the multitude of silly GUI steps.

1 Like

You may want to look at all of the KM Tokens .
There are tokens for Safari, Chrome, and FrontBrowser URL and Title.
So you don't need to copy them to the clipboard first.

FYI, you can also get Safari and Chrome page data directly by using a tell block with those apps.

Thank you again, I'll keep it in mind
I use mostly the links from Devonthink, Airmail, Bookends, OmniOutliner.

Regarding this scritp

tell application "Keyboard Maestro Engine"
  set kmCB1 to process tokens "%PastClipboard%1%"
  set kmSysCB to process tokens "%PastClipboard%0%" -- or %SystemClipboard%
  set mergeCB to process tokens "%SystemClipboard%%Return%%PastClipboard%1%"
end tell

How can I get the merged result into the active clipboard?

Or, with just AppleScript:

tell application "Keyboard Maestro Engine"
	set mergeCB to process tokens "%SystemClipboard%%Return%%PastClipboard%1%"
end tell

set the clipboard to mergeCB
3 Likes

Thanks!