Get text from Named Clipboard from KM & use in AppleScript?

This is a little more complex, but it can be done. The easiest way (that I’ve found, anyway, is to copy a “Set Named Clipboard to text” action as XML, paste the XML in the AppleScript, and replace the part of the XML containing the string with "& VariableName &" like this:

tell application "Keyboard Maestro Engine"
	set clipText to "Test"
	do script "<dict>
		<key>JustDisplay</key>
		<false/>
		<key>MacroActionType</key>
		<string>SetClipboardToText</string>
		<key>TargetNamedClipboardRedundantDisplayName</key>
		<string>Sig</string>
		<key>TargetNamedClipboardUID</key>
		<string>15F896EC-ABA6-476A-BA07-4FA02B9B71B7</string>
		<key>TargetUseNamedClipboard</key>
		<true/>
		<key>Text</key>
		<string>" & clipText & "</string>
	</dict>
</array>
</plist>
"
end tell

I’m afraid you’ll need to replicate this with your own clipboards, since this one is unique to my system, but the principle should be the same.

1 Like