Skip to content

Plain Text Notes and Message URLs in Leopard

Leopard has a small feature that I have often longed for. All my notes are text files in markdown format. URI schemes extend the usefulness of the medium. With the file URI scheme I can link to other files, and with the mailto URI scheme I can send emails. But one thing that I have wanted to do is link to a specific email (in case that it has information that I may need to refer to). Leopard has introduced a new message URI scheme that allows you to do just that. (Though why they did not implement the mid URI scheme for this purpose remains a mystery.) Marc Liyanage has a post about it, and John Gruber has a post with more details. A URL for a particular email has two parts:

  1. the message URI
  2. the message id wrapped in angle brackets

Message URLs can take any of the following syntactic forms:

message:%3cmessage_id%3e 
message://%3cmessage_id%3e 
message:<message_id> 
message://<message_id>

Both Liyanage and Gruber provide applescripts for retrieving the message id of a given email saving the message URL to the pasteboard. Gruber’s applescript is as follows:

tell application "Mail"
    set _sel to get selection
    set _links to {}
    repeat with _msg in _sel
        set _messageURL to "message://%3c" & _msg's message id & "%3e"
        set end of _links to _messageURL
    end repeat
    set AppleScript's text item delimiters to return
    set the clipboard to (_links as string)
end tell

When saved in

~/Library/Scripts/Applications/Mail/

it will appear in the script menu when Mail.app is in focus. Just select the target mail and run the script and the mail URL will be in your pasteboard ready to paste into your textfile. And if you are a keyboard fanatic who eschews the mouse wherever possible, you can use Quicksilver to run the applescript. If your text file is in markdown format, simply enclose the message URL in angle brackets.

Having the ability to link to pertinent emails really increases the usefulness of plain text notes. More so if your text editor will launch the URL for you. In TextMate, simply move the cursor over the URL and hit ⌅. Another small step in harnessing the power of plain text.

Post a Comment

You must be logged in to post a comment.
FireStats icon Powered by FireStats