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?
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:
or even better
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
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)' " & quoted form of theUrl set theUrl to "message://" & theUrl set the clipboard to theUrl end tell
/Library/Scripts/Mail Scriptsas suggested above
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!