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:
Choose to create a Service
Set the initial options:
- Service receives selected text in any application
- Uncheck “Replaces selected text”
From the Actions library on the left, select “Automator” to see its actions.
Select the “Run Shell Script” action and drag it to the workflow area or just double-click it.
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
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