View Single Post
Launching services from Applescript is not something that I've tried, but you should be able to build some kind of a link back to the original message in one of the formats listed by John Gruber in:
http://daringfireball.net/2007/12/me...s_leopard_mail

This code snippet below, from which you may be able to salvage one or two relevant elements, creates an RTF link to the selected Mail message and places the link in your clipboard. I haven't found a satisfactory way to place RTF in an OmniFocus note through Applescript, but you could usefully place a plain text version of the link, on the pattern of something like:

message:<159433453FAD4620AA3C5F19528697B6@DC8YB82J >


Code:
on run
	tell application id "emal"
		-- GET THE FIRST ITEM SELECTED IN MAIL
		set lstSeln to (selection as list)
		if (count of lstSeln) < 1 then return
		
		-- BUILD AN HTML VERSION OF A LINK TO THE MESSAGE
		set strHTML to my WrapHTML(my GetMsgLink(first item of lstSeln), "Original Message")
	end tell
	
	-- PLACE AN RTF VERSION OF THE MESSAGE LINK IN THE CLIPBOARD
	do shell script "echo " & quoted form of strHTML & "  | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf"
end run

on GetMsgLink(oMsg)
	using terms from application "Mail"
		"message:%3c" & message id of oMsg & "%3e"
	end using terms from
end GetMsgLink

on WrapHTML(strLink, strTitle)
	"<a href=\"" & strLink & "\">" & strTitle & "</a>"
end WrapHTML

Last edited by RobTrew; 2011-08-15 at 11:01 PM..