I keep a daily journal, and I like to have links to email messages, my mail client is Mail.app on OSX. I can drag-and-drop links to my journal program (VoodooPad), but I would really prefer to copy and paste them, so I have a link that looks like message://%3C30533360.1931252053580.bla.bla.bla.

3 Answers
3

Based on splattne's response, and this macosxhints entry, I figured out how to do it. Now, it's just a matter of using something like Quicksilver of FastScripts to bind it to a keyboard shortcut.

tell application "Mail"
set selectedMessages to selection
set theMessage to item 1 of selectedMessages
set messageid to message id of theMessage
-- Make URL (must use URL-encoded values for "<" and ">")
set urlText to "message://" & "%3c" & messageid & "%3e"
set the clipboard to (urlText)
end tell

Not an answer to the question that you already answered yourself, but just for the archives:

After one has saved a file from a website or an email message, one can use Get Info in Finder to find where a file came from. For an email attachment this shows the message Sender, Subject and the URL referring to that message.

Instead of Get Info, one can also use the command line to get the information:

mdls -name kMDItemWhereFroms <filename>

Using the open command such URL will make OS X activate the default application, just like it would activate TextEdit for a text file. For message: URLs, Mail.app will be launched to show the message (if it still exists).

Combined with some AppleScript from the comments at the link above:

on open these_items
set first_item to item 1 of these_items
set full_path to quoted form of POSIX path of first_item
set cmd to ¬
"/usr/bin/mdls -name kMDItemWhereFroms " & ¬
full_path & " | grep 'http:\\|https:\\|message:' | xargs open"
do shell script cmd
end open

Paste the above AppleScript in Script Editor and save it as an Application, with option Run Only. Now, when dragging any file onto that application, the source will be opened, if applicable. I am certainly not an AppleScript expert, and the above does not do any error handling, it simply takes the first file when multiple files are dropped onto the application, and it does not support directories. But one gets the idea, I guess.

(The backslashes in http:\\ above are intentional, and should not read //. The script searches for http:, https: or message:. In other words: they are not intended to be a part of http://, but together form an escaped backslash, to escape the pipe-character in the grep command.)