Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Collect the text of selected e-mails in Apps
I have several hundred e-mails which would be better dealt with as a single document. I wrote this Applescript to put the text of all selected e-mails in Mail into a new TextEdit .rtf document.

It also deletes the text 'Begin forwarded message:' to clean things up and includes a find and replace routine from MacScripter so it can be easily customized.

Here is the script itself:
tell application "Mail"
 set selectedMessages to selection
 if (count of selectedMessages) is equal to 0 then
  display alert "No Messages Selected" message "Select the messages you want to collect before running this script."
 end if
 set theText to ""
 repeat with theMessage in selectedMessages
  set theText to theText & (content of theMessage) as string
 end repeat
end tell

on replaceText(find, replace, subject) -- from MacScripter
 set prevTIDs to text item delimiters of AppleScript
 set text item delimiters of AppleScript to find
 set subject to text items of subject
 set text item delimiters of AppleScript to replace
 set subject to "" & subject
 set text item delimiters of AppleScript to prevTIDs
 return subject
end replaceText

set theText to replaceText("Begin forwarded message:", "", theText)

tell application "TextEdit"
 set theDocument to make new document
 set text of theDocument to theText
end tell
  • Copy the script above,
  • Open AppleScript Editor,
  • Paste the code in your new AppleScript Editor document.
  • Save the file to your user's Library » Scripts » Applications » Mail folder, and give it some memorable name; I called it Collect Text of Messages.scpt.
  • Select some messages in Mail,
  • Run the script from the Scripts Menu.
  • The script will create a new document in TextEdit containing the messages, which you can edit further, save, etc.

[crarko adds: I tested this, and it works as described.]
  • Currently 4.67 / 5
  You rated: 4 / 5 (3 votes cast)

Collect the text of selected e-mails in | 3 comments | Create New Account
Click here to return to the 'Collect the text of selected e-mails in' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Collect the text of selected e-mails in
Authored by: arcticmac on Dec 08, '10 08:32:07AM

For a quick and dirty alternative (no AppleScript needed, but doesn't remove message headers), you can just select all the messages in Mail and then copy/paste.

If you want, you could strip the headers from the messages while they're on the clipboard using a script something like this:
do shell script "pbpaste|perl -p -e 's/^((From:)|(To:)|(Date:)|(Subject:)).*$//g;' |pbcopy"
(of course, this is actually just a shell script wrapped up to be usable via applescript, so you could just run it from the shell too).

[ Reply to This | # ]
Collect the text of selected e-mails in
Authored by: BlackPenguin on Dec 08, '10 08:49:31AM

While I appreciate the poster's efforts to create an AppleScript for this purpose, I am curious whether he was aware that Mail is capable of saving many emails to a text file at once without the use of a script. Select the messages you want to save, go to File > Save As..., and choose either a text or RTF file format.

This will save basic headers along with the emails, which I find useful for following an email thread. They could be easily removed with a script or command-line tool, however.

[ Reply to This | # ]
Collect the text of selected e-mails in
Authored by: kiltbear on Dec 08, '10 08:55:59AM

If by "dealt with" the author means create a singular reply email then you can just highlight all the emails and hit the forward button. You could then reply inline with all the indentation loveliness preserved.

That said, I'm a fan of the "one topic per email" school of thought.

I might be able to respond to one thing NOW but the other totally separate topic might take a bit. Having separate emails per topic allows handling of the inbox to also function as a bit of a todo list. (GTD folks, please don't shoot me)

[ Reply to This | # ]