AFAICT, in Mountain Lion, OS X 10.8, the command that put a link on the clipboard for the selected message in Apple Mail has been removed. I assume this is a sandboxing issue. Since that’s a feature I use frequently when I’m making notes in DEVONthink or external editors, I wrote this script for myself as a replacement for the now-missing feature in Apple Mail. The script has a property setting at the top, which controls what the link looks like when it is pasted to your text. You have three options:
- The raw OS X message link style: message:
- A clickable RTF link that uses the text of the message’s subject line
- A clickable RTF link that uses your own text; the dialog offers the existing subject line as the starting point for entering your own text
Instructions are in the comments at the beginning of the script. Over here, I place the script in /Library/Scripts/Mail Scripts, to make the script available for all applications. (There seems to be a ML bug that scripts put into ~/Library/Scripts do not appear in the global scripts menu.)
(*
Made by korm 20120812 v1
This script places a link on the clipboard to the selected message in Mail
Three kinds of link displays (the text pasted to the clipboard) are possible.
This is controlled by the value of the p_URLtype property at the beginning of the script:
"BareLink" is the form "message:<messageID>"
"RTF" is a text link, in RTF format, which uses the message subject as the clickable text
"myText" is also a text link, in RTF format, which uses text provided by you at run time
*)
(*
The following property controls the type of link produced: comment/uncomment only one of these
*)
-- property p_URLtype : "BareLink"
property p_URLtype : "myText"
-- property p_URLtype : "RTF"
tell application "Mail"
set selectedMessages to selection
set {o_MessageID, o_Subject} to {message id, subject} of item 1 of selectedMessages
if o_Subject = "" then set o_Subject to "(No Subject)"
end tell
set o_URL to "message:%3C" & o_MessageID & "%3E"
if p_URLtype = "myText" then
set UI to display dialog "What text for the URL" default answer o_Subject default button "Cancel"
set o_Subject to the text returned of UI
end if
if p_URLtype = "BareLink" then
set the clipboard to o_URL as text
else -- if the property is not "BareLink" then it must be one of the other two options
set o_HTML to quoted form of ("<a href=\"" & o_URL & "\">" & o_Subject & "</a>")
do shell script "echo " & o_HTML & " | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf"
end if