Here’s a quick Keyboard Maestro macro to make it easier to insert images into blog posts, or any other markdown or HTML document really. The details of the macro are set up to create a Hugo figure shortcode, but the Hugo-specific bits are just scaffolding and could be swapped out for whatever you need.

You can download the macro file here, but the whole thing ended up being a bit long so I’m not going to include the usual image of the whole macro (which is 1,965 pixels tall). Let’s step through it.

A screenshot showing a portion of a Keyboard Maestro macro, prompting the user for a file and then reading it.

The first stage of the macro, prompting for the image file and then loading it onto a named clipboard.

After selecting the image, we need to load it onto a named clipboard because Keyboard Maestro’s image actions generally work on the contents of a clipboard.

A screenshot showing a portion of a Keyboard Maestro macro, reading image properties into variables.

Next we extract needed properties from the image into Keyboard Maestro variables.

Then we need to prompt the user to confirm the attributes of the figure.

A screenshot showing a portion of a Keyboard Maestro macro, of a prompt to the user to confirm attributes for the figure to be inserted.

The prompt set-up.

A screenshot showing a Keyboard Maestro prompt asking for attributes to complete an HTML figure

And the prompt itself.

Any of these can be empty, so after assembling the shortcode text blank attributes are removed:

A screenshot showing a portion of a Keyboard Maestro macro, creating the figure shortcode from provided attributes and using a regular expression to remove any empty attributes.

And then lastly the figure shortcode text is inserted by pasting, which is handy because it end up on the clipboard if anything goes wrong — like it did when I changed the focus when inserting the previous screenshot!