Easy Markdown to Word conversion in macOS

macOS text file icon
macOS text file icon
Markdown. More and more tools are using, and defaulting, to it. Microsoft Office doesn’t import or grok it natively of course (though, it should; it took me all of about 10 minutes to write a basic parser). It’s ubiquitous. Reddit has used it for at least a decade. The Things GTD app family added it a few years ago. Etc. But it’s not always the most convenient format to work with, especially if you’re under deadline pressure. So I made my life a little easier, and learned about Pandoc in the process.

1. Install pandoc

Either from a .pkg file downloaded from GitHub, or via Homebrew. I went Homebrew, ofc:

% brew install pandoc -y


2. Create a new Quick Action in Shortcuts

Open the Shortcuts program under Applications on the Mac. Click + to create a new shortcut. In the editor that pops up, in the right pane click the ⓘ at the top to show Shortcut Details, and:

☑ Use as Quick Action

     ☑ Finder.

Me, I also made a keyboard shortcut for it, ⌥⇧⌘C (that’s command, option, shift, C (for “convert”)). 

Setup the input to:

Receive Files input from Quick Actions

If there's no input:

Continue

Configuring Shortcuts to add a new Quick Action
Configuring Shortcuts to add a new Quick Action

Toggle the right pane back to the action pane and in the 🔍 search bar find “Run Shell Script”

Finding the Run Shell Script action
Finding the Run Shell Script action

If prompted, configure to ☑ Allow Running Scripts:

Setting permission in settings
Setting permission in settings

Set the shell to ‘zsh’ and pass input to ‘as arguments’ and the shell script itself to:

for f in "$@"

do

    # Get the file path without the extension

    filename="${f%.*}"


    # Run pandoc to convert the .md file to a .docx file

    /opt/homebrew/bin/pandoc "$f" -o "${filename}.docx"

done


Give it a name (in this example, “Convert Markdown to Word”):

Shortcuts app: Shell script assembled
Shortcuts app: Shell script assembled

Close the Shortcuts app and Bob’s your uncle:
Screenshot showing the new Quick Action
Screenshot showing the new Quick Action


Comments