7

In Mail, when I've selected a message, I would like to have a shortcut to copy the message_id (see my previous question) to the clipboard.

How do I manage that? Applescript, I presume?

3 Answers 3

9

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

0
1

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
0

in order to be work in Todoist, I needed to fully url encode the string (Todoist choked at the @ symbol):

tell application "Mail"
    set theSelection to selection
    set theMessage to first item of theSelection
    set theUrl to "<" & message id of theMessage & ">"
    set theUrl to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of theUrl
    set theUrl to "message://" & theUrl
    set the clipboard to theUrl
end tell
  • I saved the script to /Library/Scripts/Mail Scripts as suggested above
  • I installed also FastScript and bound the AppleScript to ⌘⌥L (for Link)

now I can hit cmd-l on any message in Apple Mail and paste the link in todoist and clicking it opens the mail again, thanks internet!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .