As of v1.7.5 of Obsidian, it's got a bug with inserting internal links in markdown format in that typing '|' to accept the link target autocompletion menu doesn't work. As a result, changing the display text on a link means doing a bunch of extra key taps and/or mousing around. I built these macros to address the gap until the bug is addressed.
I started with a single macro that could intelligently detect if there was a selection. If there was, it would insert the link, replacing the selection, and use the original selected text as the display text. If there was not a selection, the macro would prompt for the display text to use then insert the link at the insertion point.
The problem I ran into is that when there's no selection, the Cut/Copy commands in Obsidian grab the whole line, much like IDEs often do, but my macro assumes they'll be a no-op in that case. Thus, it can't reliably tell if there was a selection to start. There's a feature request to allow more control over line-based Cut/Copy, but until then, I don't immediately see a way to work around that. Thus, I split my macro into two: one for when there's a selection, and one for when there's not.
To use, simply run the appropriate macro. The one for no-selection will prompt you for text to use as the display text, while the other will not. From there, they both trigger Obsidian's autocomplete link insertion UX and will wait for up to 30 seconds for you to navigate that. When you've found the file you want to link to, press return to accept it -- this will trigger the macros to continue running and insert the links. You can't use the mouse to select the autocomplete target because the macro specifically uses the return key as a continuation flag.
This is all a little janky, but it's been pretty helpful to me, so maybe it'll help someone else, too.
Setup background points:
-
I've set up the macros with the same keyboard shortcut trigger (cmd-opt-K) so that I'm presented with the conflict palette to choose one.
-
I'm including the unified version. Depending on when/if either issue gets addressed on the Obsidian side, it may be useful in the future.
-
The unified version uses a subroutine macro to determine if there's a selection, so I'm including that, too.
Here you can download the macros:
Obsidian link macros.kmmacros (48.0 KB)
And here you can get a preview of them: