Markdown Preview Text Service for Mac OS X

So, to have a nifty way to preview any text you’re writing in Markdown on OS X 10.6, you can create a text service using Automator. For now, we’re going to assume you have a working installation of a command line Markdown to HTML converter. In this example we will use MultiMarkdown, but as long as you know how to use yours from the command line, you should be able to modify it to your needs.

This is really just mostly the first Automator workflow step from my previous post about making a service to be able to compose with Markdown in Mac OS X Mail.

To make this Automator service:

  1. Open Automator

  2. Choose to create a Service

  3. Set the initial options:

    • Service receives selected text in any application
    • Uncheck “Replaces selected text”
  4. From the Actions library on the left, select “Automator” to see its actions.

  5. Select the “Run Shell Script” action and drag it to the workflow area or just double-click it.

  6. Replace the sample command “cat” with:

    ~/Library/Application Support/MultiMarkdown/bin/MultiMarkdown.pl > /tmp/tmp.html open -a Safari /tmp/tmp.html

If you have the original Markdown installed, you will need to obviously change the path name to reference it instead, such as:

  • /Library/Application Support/MultiMarkdown/bin/MultiMarkdown.pl

or maybe

  • ~/bin/Markdown.pl

The full path is needed since (I think) the script will run in a non-interactive shell, which may not have all the $PATH directories that your interactive shell sets up depending on which profile script you do that in.

You could also add SmartyPants to the mix with:

~/Library/Application Support/MultiMarkdown/bin/MultiMarkdown.pl | ~/Library/Application Support/MultiMarkdown/bin/SmartyPants.pl -2 > /tmp/tmp.htmlopen -a Safari /tmp/tmp.html