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

**URL:** <https://forum.obsidian.md/t/a-keyboard-maestro-macro-to-create-markdown-links-in-different-situations/8037>\
**Category:** Workflows & Templates\
**Tags:** keyboard-shortcut\
**Created:** [November 2, 2020, 7:15am UTC](https://forum.obsidian.md/t/a-keyboard-maestro-macro-to-create-markdown-links-in-different-situations/8037 "2020-11-02T07:15:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![OlivierPS](https://forum.obsidian.md/user_avatar/forum.obsidian.md/olivierps/32/2130_2.png) [@OlivierPS](https://forum.obsidian.md/u/OlivierPS)\
**Post date:** [November 2, 2020, 7:15am UTC](https://forum.obsidian.md/t/a-keyboard-maestro-macro-to-create-markdown-links-in-different-situations/8037/1 "2020-11-02T07:15:58Z")

</div>

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](https://forum.obsidian.md/uploads/short-url/y9oZrPqym9xQZ6MmwFbnDOGChlq.zip) (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”.
