mail messages to word documents

Peter:

Glad to hear it was something simple, at least for starters. The current script does not overwrite, it appends to the end of every Word document if the name is the same. For instance, if you have 6 messages with the subject line “My Dog Smells Badly”, every time the script runs, Word will try to open a document with that name. If it succeeds, it will add a few returns to the end of the document, then paste in the text the current message. So, by the time it is finished, you should have a single Word document entitled “My Dog Smells Badly” with the content of 6 messages contained therein. That is the essence of the try block in the MakeWordDoc handler. Please try that out, and page down in Word to make sure that it functions for you as it is written.

As for where to place the magical folder with all these messages, that is pure cake. The very first line of the script defines the location of the final folder, but as written, of course, you only get one folder. If you want to sort out folders, you would most likely do well to copy the script (once it is working as you like), save different copies for different locations, and use Mail rules to choose which script is called from which mailbox. I am confident there is a way to get a single script to do the sorting, so we could work on that, I suppose, as well.

The date should not be a problem. I will look into that today sometime. I have a bunch of stuff to do in my office, so I don’t know when I can get back to this, but it should be soon.

Hi Craig

Just a note to thank you for your help. I finally figured out how to put the date in (at least I hope I have done in correctly) and also how to select the destination file before I start. Have attched my script in case you have time to see if there are any obvious flaws. As you can see I have added very little but pleased I got it going.

set folder_path to (choose folder) as string
–display dialog folder_path
set desk_path to folder_path
global desk_path
–display dialog desk_path
tell application “Mail”
set m_boxes to the name of every mailbox
set this_box to choose from list m_boxes
repeat with a_mess in (every message in mailbox (item 1 of this_box))
–display dialog this_box
–set my_date to (a_mess’s date received) as string
–display dialog my_date
my MakeWordDoc((a_mess’s content), (my TestFixSubject((a_mess’s subject))), ((a_mess’s date received) as string))

end repeat
delete every message in mailbox (item 1 of this_box)

end tell

on MakeWordDoc(con, sub, dat)
–display dialog sub
–display dialog desk_path
set file_nm to (desk_path & sub)
tell application “Microsoft Word”
try
set newDoc to open file name file_nm
insert text " " at end of text object of newDoc
on error
set newDoc to make new document
end try
insert text con at end of text object of newDoc
insert text dat at end of text object of newDoc
–this name has colons in it and is to long
save as newDoc file name file_nm
close every document
end tell
delay 5
end MakeWordDoc

on TestFixSubject(str)
set fixed_string to {}
set bad_char to {“:”, “/”}
repeat with c from 1 to (count every character in str)
if bad_char contains (character c of str) then
set end of fixed_string to “-”
else
set end of fixed_string to (character c of str)
end if
end repeat
fixed_string as string
end TestFixSubject

Once again many thanks, this is the first scrip that I have got to work and it is really useful. All I have to do now is automate it some.

Peter

Been following this thread and have a question / suggestion.

Is there any benefit to actually using Microsoft Word to write the file? Why not just go directly to a text file and give it a .doc extension?

-N

Probably not but most of what I do is in Word so it is far easier for me to use that program. Do you see some advantage in making it a text file with a doc extension? I presume the doc extension is so word will open it. One of the disavantages of doing it this way is that some files are unnecessarily large because of the fact that emails have habit of becoming threads. When I mentioned automating it one of the things I want to do is strip out text already saved, but that is far away from my limited ability at present.

Peter

Writing directly to file and bypassing Word will give you an incredible speed increase. I can’t think of a downside if you’re only bringing text in.

May not be so hot for adding onto the same doc later though. Just a thought.

And yes, once the .doc extension is on, it’ll open in Word by default

-N

Thanks for that, but not sure I know how to make it text rather than word. You are correct one of the problems is speed, the other I did not appreciate (even think of) is attachments. I have been trying to work out a way you can indentify if a message has any and if so save them, if not with the text(word) file at least in the same folder, so far no luck any suggestions much appreciated.

Thanks

Peter