Mail.app: Get URL for selected message with AppleScript and TextExpander

I often use message://<message-id@example.com> URLs to reference a specific email in OmniFocus or Evernote: clicking one of these URLs will automatically open up the source message in Mail.app.

There's not a great way to get these very handy message URLs without AppleScript, so based on this SuperUser answer, I created a TextExpander snippet.

Now, when I type xmsg, TextExpander will insert the message URL for the selected message in Mail.app into whatever application I'm working in.

Here's the TextExpander snippet, and here's the AppleScript:

tell application "Mail"
	set selectedMessages to selection
	set theMessage to item 1 of selectedMessages
	set messageid to message id of theMessage
	-- Make URL (must use URL-encoded values for "<" and ">")
	set urlText to "message://" & "%3c" & messageid & "%3e"
	return urlText
end tell


🌟 Was this page helpful? Please let me know with this quick, 3 question survey.

5 responses
Nice tip! I will use it for Evernote and other Apps where I want to link to an email. For OmniFocus I still prefer the mighty Clip-O-Tron http://support.omnigroup.com/omnifocus-clip-o-tron as it also clips from other apps to OF2. Will keep reading your site, nice work.
@rugydp – That's a great point. I used the OmniFocus quick entry for the gif because it was convenient, but the Clip-O-Tron is definitely the way to go. I primarily use this TextExpander snippet with Evernote and when I want to reference multiple messages in an OmniFocus item note.
This is great! Perfect for Evernote. Thank you for sharing!
This is really great. Thanks.
1 visitor upvoted this post.