How to get values of %SystemClipboard% and %PastClipboard%1% in AppleScript?

applescript

#1

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?


#2

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


#3

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.


#4

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.


#5

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