Link to Apple Mail Message Anywhere on Your Mac With Apple Script


#1

Gang,

Here’s a cool post with an AppleScript that lets you create a link to an Apple Mail message anywhere on your Mac.

And here’s a demonstration video.


#2

I might try to see if I can get that to work with Airmail. It would be handy for me if it did.


#3

For Airmail and MailMate (probably others), there is a shortcut:

Command+Shift+Option+C ( ⌥⌘⇧+C )


#4

Looks like in Airmail it’s Control-Command-Option-C, not Shift. Thanks for the lead on that though. I will make it part of a Keyboard Maestro or Textexpander shortcut.


#5

That AppleScript won’t work with AirMail. Also note the airmail links just work with Airmail on all platforms (but they do work).


#6

Interesting script. I wrote my own version many years ago, which is attached to my Keyboard Maestro menu that opens when I’m using mail. For me, I wanted the option to have either a “plain link” (message://) or a markdown-formatted link that includes the message subject name.

    tell application "Mail"
	try
		if selection is {} then error
		set theMessage to the first item of (selection as list)
		set theID to the message id of theMessage as string
		set theLink to "message://%3c" & theID & "%3e"
		
		set linkType to display alert "Markdown Link" buttons {"Yes", "No"} default button 2
		set answer to button returned of linkType
		
		if the answer is "No" then
			set the clipboard to theLink
		else
			set the clipboard to "[" & subject of theMessage & "](" & theLink & ")"
		end if
	end try
   end tell

Example

[L.L.Bean Shipping Confirmation](message://%3c0.1.14F.58B.1D4866D483CDC16.0@omptrans.e1.llbean.com%3e)

If I have a multi-selection of messages, I have a version of this that will make a list of all the links in markdown format, put the list on the clipboard, for pasting into a markdown-compliant editor.


#7

Here’s your script for Airmail:

tell application "Airmail 3"

set theMessage to the selected message
set theLink to the selectedMessageUrl
set linkType to display alert "Markdown Link" buttons {"Yes", "No"}
set answer to button returned of linkType
if the answer is "No" then
	set the clipboard to theLink
else
	set the clipboard to "[" & subject of theMessage & "](" & theLink & ")"
end if

end tell