Open Mail URI Snippet

Hi, longtime user, first time poster. :grinning:

I have an AppleScript that will copy the URI to an email from Apple mail and place it on the clipboard.
In the clipboard manager in UnClutter, it appears as a blue, clickable link and indeed opens the referenced email.

If I paste that URI into a Tinderbox note, or a text editor, it is no longer a “live” hyperlink.

FWIW, here is the text of the URI: message://%3cdiscourse/post/

The same is true for a web URL, but selecting the text of the URL offers the Link extension in PopClip, and I can open the link in Safari.

I was hoping to add the same functionality to Mail URIs. Someone in the Tinderbox Forum pointed me toward the DevonThink Forum about custom URI schemes.

Kind of an old link, and it seems like “Snippets” ought to be the answer I’m looking for.

I read the docs and created this Snippet:

#popclip custom URL scheme Apple Mail
name: Mail URL
icon: symbol:<mail>
url: message://{popclip text}

When selecting the text of the URI, PopClip appears and Mail URL is at the end of the command bar. Clicking that, I get an error as shown in this screenshot:

I’m hoping it’s something simple I’m overlooking. I’m not very skilled in this sort of thing, but I’m usually able to stumble my way through it with a little (or a lot of) help.

Can anyone offer some insight into how I should modify the Snippet, or is what I’m trying to accomplish simply not feasible?

(I suppose I could rename this to Open Mail URI or something less confusing, but I don’t think it’s the root of my issue.)


Hi @dmrogers99, welcome to the forum.

The trouble is that the extension is URL encoding the the selected text, then prepending message:// to it — but the selected text itself is already a properly formed URL. Essentially is is encoding the message URL in another message URL.

What we want to do is open the selected text directly as a URL, without any additional encoding. The easiest way is with a JavaScript snippet line this:

#popclip custom URL scheme Apple Mail
name: Mail URL
icon: symbol:envelope
javascript: popclip.openUrl(popclip.input.text)

As an aside though, effectively what we have made here is an extension that opens ANY text as a URL.
(Though you could add a regex to make it only appear of the text contains message://)

Another way to accomplish this is to tell PopClip that it can treat message: URLS as openable with the Open Link action. I’ve added this to PopClip’s code (it has a hard coded list) for the next version. And you can configure it with the following terminal command:

defaults write com.pilotmoon.popclip OtherURLSchemes -array-add message

then Quit and restart PopClip

1 Like

Thanks for the quick reply and you will be unsurprised to learn that it worked as advertised!
Much appreciated.

1 Like