Creating Links to Messages in Apple Mail With Shortcuts and AppleScript

John Voorhees, writing at MacStories:

For the past several weeks, I’ve been using Mail exclusively on
all of my devices, which has been a refreshing change of pace.
Still, it’s not perfect. Of the features I use most in third-party
mail clients, the single biggest shortcoming of Mail is its clunky
implementation of deep linking.

I drop links to email messages in my notes and tasks all the time
as a way to quickly access important contextual information.
Mimestream offers Gmail URLs, and Spark can create its own
app-specific and web URLs right within those apps’ UIs.

In contrast, on iOS and iPadOS, you can only link to a Mail
message by dragging it out of Mail into another app’s text field.
I’ll take it, but I’d prefer if I could quickly generate a link
from the share sheet or with Shortcuts instead. The situation on
the Mac isn’t much better, requiring users to resort to
AppleScript to construct a URL that links back to a Mail message.

With weeks of Ventura testing ahead of me, I decided to see what I
could do to improve the situation.

His solution relies on an AppleScript I shared here 15 years ago — which I still use, unchanged, several times per week. Say what you want about AppleScript, but when you find something that works it tends to keep working.

The basic idea here is that Apple Mail has long supported a message:// URL protocol for creating links to specific email messages. Every legitimate email message ever sent has a unique message ID; Mail’s message:// URLs take the form of message://<UNIQUE-ID-HERE>. For compatibility reasons, the angle brackets are best encoded as %3c (for <) and %3e (for >). Without knowing it, if you use Apple Mail, you’ve probably made use of these URLs. For example, when you create a calendar event from a date in an email, that event links back to the message from whence it came, and that link is a message:// URL.

But 15 years after adding support for these URLs, Apple still hasn’t exposed a direct way to copy them from any given message other than drag-and-drop. And when you drag a message from Mail to the Finder, you get a file with the exported contents of the message, not a URL clipping (like you get when you drag a URL from Safari to the Finder). Try dragging from Mail to Notes to get a link. Hence the continuing utility of my AppleScript — it’s still the best way to just put the messages:// URL for a given message on the clipboard.

Related Articles

Skip to content