A *Keyboard Maestro* macro to create *Markdown* links in different situations

You may have noticed how difficult/convoluted it is to create Markdown links, even with different helpers, plugins, etc. So I’ve come with a personal solution programmed in Keyboard Maestro. I’m offering it in the form of a macro library, attached. (I’m not at all familiar with this sharing part of Keyboard Maestro and I hope I did it correctly). → Create Markdown link.kmlibrary.zip|attachment (2.8 KB)

The problem is that we have different configurations to adress, when we hit the “Make Link” key [CMD–K] :

  • with or without some selected text
  • with or without a link in the clipboard

My macro adresses the four situations like this :

Clipboard doesn’t contain a link Clipboard contains a link
Nothing is selected • types []()
• puts the cursor inside the brackets
• types [](TheLink)
• puts the cursor inside the brackets
Some text is selected • types [TheSelectedText]()
• puts the cursor inside the parenthesis
types [TheSelectedText](TheLink) and leaves the cursor right after the final parenthesis

By “link”, I mean “any string containing characters, followed by “://” followed by characters”. Thus, X-callback URL calls are also considered as links and the macro works the same with them.

NB : As I’m not a programmer, I couldn’t find a good way to know, in Obsidian, wether text is selected or not. So, in Obsidian the macro works best if you have text selected. But anywhere else, it works / should work fine. — any workable solution most welcome!

I wish the Obsidian developers would offer something like this “out of the box”. Currently, in my opinion, it’s “half done”.