Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 5 down vote accepted

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

share|improve this answer
1  
Thank you, you've been extremely helpful! – Michiel de Mare Jun 28 '12 at 20:58
    
This one helped me too. Thank you! – ephsmith Jun 28 '12 at 21:41

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
share|improve this answer

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!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.