I'm a developer, and I'd like to be able to distinguish blocks of code from regular text, when I write emails.

Basically I wanna be able to do this. In the Mail app, (or Sparrow!).

Is there a way to do this with a shortcut, or macro, etc so that I don't have to reach for the mouse every time and change like 20 font attributes?


The magic behind the formatting on StackExchange is a great perl script called Markdown. Download it, and double-click the resulting Markdown_1.0.1.zip file.

Then, in terminal, type

chmod a+x ~/Downloads/Markdown_1.0.1/Markdown.pl
sudo cp ~/Downloads/Markdown_1.0.1/Markdown.pl /usr/local/bin/

Once you have that done, you can create a Service in Automator.

The service you create receives rich text in any application. Uncheck the box that says Output replaces selected text.

Your service will contain two actions:

The first action is Run Shell Script. Here is the shell script:

/usr/local/bin/Markdown.pl | /usr/bin/textutil -stdin -stdout -format html -convert rtf | /usr/bin/pbcopy

Your section action is Run AppleScript. Here is the AppleScript:

tell application "System Events"
    keystroke "v" using {command down}
end tell

Save the service, and, if you wish, assign it a keyboard shortcut using System Preferences » Keyboard » Keyboard Shortcuts » Services

Then, you can type text using the formatting codes you use on this site, and run this service to generate formatted text. This will only work if your mail messages are set up as Rich Text -- if you have plain text mail messages, running this service will simply erase the contents of your message, as your rich text formatted by the service will not be able to be pasted.

  • 1
    Cleaner than "rendering" the HTML in Safari. I like it.
    – jaberg
    Mar 19 '12 at 0:25
  • Sadly, this still doesn't work for me. I now get "Failed to write output" and again it looks like it's caused by the second part (pasting). I'm running 10.6.8 with Automator 2.1.1. I'm guessing it's a versioning issue.
    – pseudosudo
    Mar 19 '12 at 13:34
  • 1
    If anyone has debugging issues, we have a room: chat.stackexchange.com/rooms/info/2830/…
    – jaberg
    Mar 19 '12 at 14:35
  • This is brilliant. For those of you who prefer reStructuredText: /path/to/rst2html.py -q --stylesheet=/create/a/style.css --embed-stylesheet | /path/to/textutil -stdin -stdout -format html -convert rtf | pbcopy
    – Shabbyrobe
    Mar 30 '12 at 1:21
  • Holy crap this is cool!!! Works perfectly.
    – Mike N
    Mar 2 '17 at 9:09

Assuming you're comfortable sending HTML mail you could use Markdown to format your email message and create an automator service to convert, render and replace your markdown with formatted text.

ᔥ Ryan Gray: Markdown Compose for Mac OS X Mail

[W]hat I had to do was to save the HTML generated from the Markdown conversion to a temporary file, then open that in Safari, have Safari select all and copy to the clipboard (copying an HTML object), then having Mail paste it – replacing the selected Markdown text. So, the service workflow takes the selected text, but does not itself replace the selection directly.

Instructions for creating this service are provided in the article. In addition to providing an explicit path to the markdown.pl file in your Automator script, be certain that you make markdown.pl an executable file.

chmod a+x your/path/to/markdown.pl

Note: With the demise of Posterous, the original link to Ryan Gray's article broke. I've edited the answer to point to a version archived at The Internet Archive Wayback Machine. ↬Dominique for bringing the broken link to my attention.

  • Ryan Gray's article is no longer at the address given now that Posterous is gone. However, Brett Terpstra has an awesome set of OSX services for Markdown!
    – Dominique
    Jun 18 '13 at 13:16
  • Yes, I use Brett's Markdown Services constantly.
    – jaberg
    Jun 27 '13 at 14:58

You can install Markdown Service Tools and then follow the instructions by Tobias O’Leary. Recommended!

  • Glad to know someone is using this!
    – Tobias
    Oct 4 '17 at 3:59

I know this one is a little old -- so here is an update of sorts. I had a hard time getting that answer's shell script to work correctly.

I had installed Markdown via brew.

On the shell script "Pass input:" set to "as arguments". I had success with this variation on the shell script:

/usr/local/bin/markdown <( echo "$1" ) | /usr/bin/textutil -stdin -stdout -convert rtf -format html | /usr/bin/pbcopy

The AppleScript remained the same.

enter image description here


I use a shell script like this:

echo "<style>
$(cat /Applications/Marked.app/Contents/Resources/swiss.css |
sed 's/&/&amp;/g;s/</\&lt;/g;s/>/\&gt;/g')
$(cat | pandoc --strict -p)" |
textutil -stdin -stdout -inputencoding UTF-8 -format html -convert rtf |
LC_CTYPE=UTF-8 pbcopy

pandoc --strict -p acts like Markdown.pl and preserves tabs.

-inputencoding UTF-8 is required to preserve non-ASCII characters. LC_CTYPE=UTF-8 is not needed if LC_CTYPE is already set to a UTF-8 locale.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .