Copy message_id from selected message
That's doable as well. Paste the text below into AppleScript Editor (find it simply with Spotlight by typing "⌘Space AppleScriptEditor" and hitting the enter key when it's highlighted).
tell application "Mail"
set theSelection to selection
set theMessage to first item of theSelection
set theUrl to "message://<" & message id of theMessage & ">"
set the clipboard to theUrl
end tell
You can test this by pressing the run button in the editor (with a message selected in Mail). Once you're satisfied, save the script as "Copy Message URL to Clipboard" under either:
/Users/yourusername/Library/Scripts
or even better
/Library/Scripts/Mail Scripts
To save it to the Mail Scripts folder, first save it to your Desktop. Then open a Finder window and do ⇧⌘G, type the path to the Mail Scripts Folder and hit enter to view that folder. Now drag your newly created script to that folder.
While you're in the AppleScript Editor, you probably want to go ahead and enable the AppleScript Menu for the toolbar so that you can find and run the script easily. To do this, open AppleScript-> Preferences (⌘,) and check the box labeled "Show Script menu in menu bar". Now you'll be able to access the script easily from
Scripts menu -> Mail Scripts->Copy Message URL to Clipboard
Reference: Some of the AppleScript displayed above was snipped from a portion of this AskDifferent answer
The correct script is:
tell application "Mail"
set theSelection to selection
set theMessage to first item of theSelection
set theUrl to "message:%3C" & message id of theMessage & "%3E"
set the clipboard to theUrl
end tell