Using KBM actions (not AppleScript) to insert link to frontmost Chrome Window

I am trying to solve a problem using KM actions, as opposed to an AppleScript because I want to be able to make modifications and adaptions in the future.

The macro below inserts the frontmost Chrome Title → highlight the title → create Link (Cmd-K) → insert the URL

I want to end up with a robust macro which yields:

title of window

instead of

title of window

The problem with the macro below is the section action which highlights the title. It is not robust and creates unpredictable outcomes when the title is multi line (as when the window I am working in is narrow) or when there is text on the same line behind the title (which is selected and included in the title to create the link)

thanks in advance for your time and help

I don't have Chrome, so I tested this with Safari. Also for testing, I used TextEdit, so you may need to adjust this for whatever app(s) you're using. And credit to @peternlewis for the approach he showed in this thread about getting the cursor position, which I mildly reformulated to circumvent AppleScript which you wanted to avoid.

Two notes: As designed, this macro assumes there will be no text after the point at which you're inserting the Chrome title. And where H3R3 is shown in the macro, there is a space after it.



Sorry, ronald, but you will need a script, specifically a shell script, to create a rich text hyperlink that you can paste into any rich text document.

There may be a few, app-specific, workarounds that involve pasting the link text, selecting the text, and then use the app's menu to create a hyperlink. It can be done, but is not very robust.

The shell script is very simple, and there should not be a need to modify it.
There are many, many things that KM native non-script Actions can do, but this isn't one of them.

Here's the Shell Script:


This has been used by many people for years.

Here's the full Macro to Set the Clipboard to a Hyperlink:

All you need to change are the magenta Actions that set the data for the Shell Script.

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.


MACRO:   Set Clipboard to Rich Text RTF Hyperlink Using Shell Script [Example]

-~~~ VER: 1.0    2020-07-21 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Set Clipboard to Rich Text RTF Hyperlink Using Shell Script [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


a superb macro which I added to many palettes. thanks very much !!

thank you very much. Although I decided to go with @JMichaelTX 's macro, I will definitely keep in mind the trick of using Find to highlight and insert a link