in applescript

Paste email link from selected MailMate message(s)

David Sparks posted about a clever idea to instantly link to Apple Mail messages from anywhere:

I’ve always like the way OmniFocus can create links to Apple Mail messages when saving an email as a task…

I’ve now got a script that can do that anywhere via a text expander snippet…

Once you’ve installed it, just type “elink” in any app that can take a URL and you create a link to the currently selected email message. I use it all the time in Notes and Calendar note fields but it really works anywhere.

Here’s an adaptation that works with MailMate and Keyboard Maestro:

Get email link macro

MailMate doesn’t have a ton of AppleScript support, but there is built-in Copy Links to Messages bundle command, and you can execute bundle commands via AppleScript.1

So it was just a matter of stringing together

  1. A typed keystroke trigger (I’m using elink, Spark’s shortcut of choice)
  2. MailMate’s copy command
  3. Paste

For good measure, the final action restores the prior clipboard contents.

Download on the Keyboard Maestro forum

  1. This is why I used Keyboard Maestro instead of TextExpander: TextExpander needs scripts to return a specific value for typing, but the MailMate script is run indirectly, puts the url on the clipboard, and returns empty. With Keyboard Maestro, the next step (pasting the clipboard) is trivial.

For those with something to say: