Update: This post is long out of date. Zettt and I worked together to come up with a better, faster way to do the same thing with Keyboard Maestro. Find his latest version of his Keyboard Maestro Markdown Library to see it in action.

Introduction

If you write in (Multi)Markdown and have Keyboard Maestro, I recommend you check out Andreas’s (@Zettt) Keyboard Maestro Markdown library, which makes it easy to write in Markdown through various schemes such as easily wrapping selected text with various special characters1; creating inline links, reference links, and image tags with fill-in templates; making ordered and unordered lists from selected lines of text; and several others. His videos clearly explain how to use them. He also chose a brilliant hotkey schema that makes it easy to remember all the options once you learn one or two.

He’s currently working on some updates with the release of KM6, but that got me thinking about a modification I wanted to make.

Problem

As it stands now, after placing the footnote, the cursor is left at the bottom of the document, rather than back in the text where the writing will continue.2

This slight break in workflow is an unfortunate drawback of creating footnotes3. Some text editors do have the ability to remember cursor position so that it can be returned it to the original position, but one of the reasons I use Keyboard Maestro for these tasks is so they will be editor agnostic since I’m constantly changing my editor.

Solution

Keyboard Maestro 6 added a cursor position token: %|%. Since the original macro involved two paste actions separated by moving the cursor, I was going to need to combine them into one paste action. Instead of using ⌘-↓ to move the cursor to the bottom of the text, I use ⇧-⌘-↓ to select all the text from the cursor position to the bottom of the document. I then cut (⌘-X) this to the clipboard. Finally, I paste a concatenation of the footnote tag, the cursor position token, the clipboard, and the footnote:

[^%Variable%MMDFootnoteTag%]%|%%CurrentClipboard%

[^%Variable%MMDFootnoteTag%]: %Variable%MMDFootnoteText%

The extra carriage return is because, in my experience, you need to have a blank line between footnotes, unlike reference links, to get them to display correctly. Fletcher Penney recommends this format with regards to bibliography support in Multimarkdown.

The final macro looks like this:

If you’re paying close attention, you might notice that I also added a default value for the footnote tag, which is just the date and time in ICU yyyyMMddHHSS format.

I think this makes it much easier and natural to write Multimarkdown footnotes, which may turn out to be a bad thing since I’m suddenly adding them all over the place.4

You can download the macro here.

  1. Asterisk, double asterisk, quotation marks, parentheses, brackets, and backtick quotes. 

  2. The macro is written to insert the footnote tag at the current cursor position, ⌘-↓ to move to the bottom of the document, and then paste the footnote. 

  3. Unless you make inline footnotes and convert them using Brett Terpstra’s system service. I tried it, but too often it wouldn’t work because I was trying to nest a footnote inside a link inside something else. 

  4. Like this one, for no good reason other than I could.