Obtain Apple Mail item URL?


Although I appreciate, and use, the Apple Mail Plugin for DTPO very much there are times when I would like to have a direct link back to the message in Mail. Until now I’ve been dragging and dropping the messages into DTPO RTF files. However, I’d like to add Apple Mail item URLs to the URL field of DTPO files.

I can’t seem to find anything describing how to accomplish these in the DT forums or elsewhere. But then again, I’m not certain that what I need is actually called a “Mail item URL” nor am I certain that this approach is the best.

Does anyone have any thoughts on this?




I don’t know if there are simpler ways, but this applescript does the job:

tell application "Mail"
	set selMessages to selected messages of message viewer 1
	repeat with curMessage in selMessages
		get curMessage
		set messageid to message id of curMessage
		set mailUrl to "message://" & "%3c" & messageid & "%3e"
		-- do something with mailUrl
	end repeat
end tell

If it’s in the right place, ie, ~/Library/Scripts/Applications/Mail/, and ran from the OS X Scripts menu, it will run through all selected messages, construct a URL for each (these look like “message://BunchOfCharacters”) and then do something with it (which I left blank).

Hope this helps.

Thanks, that sounds helpful. All I really want to do is add it to the clipboard. Is that possible?

If what you are looking to do is to get the URL for individual messages (rather than for a selected group of messages), then you can copy this to the clipboard from Mail. Use ‘Edit>Copy Message URL’ or Command-Option-Control-U. You can paste that into the URL field of DT if you would prefer it to the email to sender URL that DT adds by default.


This is precisely what I would like to do. But I don’t have that option under my Mail Edit menu. I also am not getting a useful result from the command you list. It’s strange because I know I’ve done this before. I’m using Mail (4.3). Is there something I’m missing?


I’m still using Leopard Mail 3.6, so perhaps the menus have changed for Snow Leopard. Here is a script that will copy the URL(s) of the selected message(s) and put the URL(s) on the clipboard. Hope it helps.

tell application "Mail"
	set _sel to get selection
	set _links to {}
	repeat with _msg in _sel
		set _messageURL to "message://%3c" & _msg's message id & "%3e"
		set end of _links to _messageURL
	end repeat
	set AppleScript's text item delimiters to return
	set the clipboard to (_links as string)
end tell


Your script works perfectly for my application. Thanks for sharing it!