MACRO: Set Clipboard String for Type V1.0

MACRO: Set Clipboard String for Type V1.0

Requires KM v11 or higher

It's possible someone already created a macro like this. I didn't spend a lot of time searching.

If there is another macro that does this, all I can say is this one has one Comment action, and a 4-line JXA script, so it's pretty clean.

PURPOSE:

Allows you to set the clipboard to a string, speficying the clipboard type.

Clipboard Types

Here's a couple of clipboard types to get you started:

Type Result
public.html HTML. With this format, you can paste the clipboard into RTF fields, including KM's Comment action, and get formatted text.
public.rtf If you have the plain text for some RTF, you can put it on the clipboard with this type. I think, anyway, I never tried it. (What do you want for free?)
com.stairways.keyboardmaestro.macrosarray You can put the XML for a KM Group on the clipboard with this text, and assuming you formatted the XML correctly, you can paste it into a new KM Macro.

Examples:

This macro comes with two "example" macros:

  • Set Clipboard String for Type Example - HTML/RTF
  • Set Clipboard String for Type Example - Macro

See the comments inside them for more info.

Reusing the code

This macro is actually just one small JXA script, and it's really short. If you want to use it somewhere, just copy the action wherever you want.

The JXA script expects two variables to be set: "Local_Text" and "Local_Type".

If you create your own "Execute a Javascript" action, make sure you click the down-arrow next to the JXA code, and check "Modern Syntax".

VERSION HISTORY

1.0 - Initial Release

INSTALLATION

UPGRADE INSTRUCTIONS:

  1. Delete the old macros first.

Set Clipboard String for Type.v1.0.kmmacros.zip (4.0 KB)

Download the macro file, unzip it, and double-click the .kmmacros file. In addition to the two macros mentioned above, it will import this macro:

  • Set Clipboard String for Type v1.0

3 Likes

Hi, @DanThomas. Very nice subroutine; thanks for sharing!


Here's a simple example caller that converts a markdown link to an RTF web link.

Download: Set Clipboard String for Type Example - HTML-RTF (Link).kmmacros (5.2 KB)

Macro-Image



I haven't seen a similar subroutine on the forum; however, with the macro Copy as Markdown Link by @ComplexPoint the link created has two variants/flavors: plain text and RTF.

What's really cool about Copy as Markdown Link is that when the created link is pasted in a text editor, it appears as plain text (i.e., [label](URL)); otherwise as RTF (e.g., within a Comment action).


Dan, with my example caller I wanted to point out a subtle detail...

As uploaded when I ran the caller, I created the displayed link and then typed the remainder of the text.

Comment.kmactions (1.3 KB)

Keyboard Maestro Export

With the example caller, here's the HTML:


Without the  , here's what occurs when the link is pasted and the remaining text is typed.

Comment.kmactions (1.3 KB)

Keyboard Maestro Export


I've noticed the same issue when using Copy as Markdown Link and pasting into a Comment action.

1 Like