Barry,
From: Barry Wainwright <[EMAIL PROTECTED]>
Reply-To: "Entourage:mac Talk" <[EMAIL PROTECTED]>
Date: Wed, 01 May 2002 10:22:10 +0100
To: "Entourage:mac Talk" <[EMAIL PROTECTED]>
Subject: Re: Would like a printed list of messages in a Folder
This is the second time in recent days that I have seen this request, so here's a script to summarise what you want.
It will create a tab-delimited text summary of the selected message, and put this data on the clipboard, ready to be pasted into word, excel or whatever you find appropriate.
It's been done quickly, so there's not been a lot of testing, but it seems to cope with multiple attachments, long recipient lists, recipients without full addresses etc. If you find it trips up on anything, let me know and I'll tweak it. I have only tried the script with Entourage vX, but I can see no reason why it wouldn't work in v2001 as well.
Post the script below into script editor and save it as a compiled script in the 'Entourage Script Menu Items' folder that you will find in your MUD folder.
(note, this message has been posted as HTML to avoid line wrapping in the script. If you can’t get the script to compile, mail me off-list and I’ll send you a precompiled version)
I will (in a day or two) send the script off to AppleScriptcentral.com, but I’ve submitted a few there in recent weeks and they haven’t been posted yet (are you there Eric?) so I don’t know how long it will take to get them up there.
-- Start of Script --
[snip]
-- End of Script --
Thanks a lot for the quick script. It was exactly what I was seeking; actually even more since I get a list of all the attachments rather than just an indication that there are attachments. In testing it I did not find any errors, but did feel a need for a couple enhancements.
(1) The date field was complete, but did not allow for expected sorting in Excel. I dug in the Entourage dictionary, the applescript guide, and the Apple webpage to find a way to get the date and time without the day of the week. My hack is in the revised script below. Is there a better way of doing it?
(2) The recipient display names ended up with a lot of extra double quotes. If there was no display name then there was an empty set of double quotes. If the display name already had quotes (single or double) around them then they ended up with two sets of quotes at the front and back. I also ran into a strange occurrence — the first displayed name did not have any leading quotes, even if they were in the original display name and it was followed by no quotes if there were none in the original display name and two quotes otherwise. The second and third recipient always showed two sets of quotes before and after the displayed name if the original display name contained quotes and one set of quotes before and after otherwise.
For item (2), I decided that I only needed the display name (unless there was none — and then I used the address) for both the sender and the recipients. See my additions below.
I have no real background in scripting so I kind of use the bruit force method. I am always interested in learning more, so let me know if there is a more elegant way to accomplish what I did.
One other thing I did once I got into Excel to make the sorting more useful there was to remove the “RE: “ and “FW: “ leaders on replies and forwards. It would be nice to remove them from the subject line while creating the list if it is easy. Since the links are lost in the mbox file, at least being able to sort the list by subject is helpful.
Thanks again Barry. Following is the script with my modifications highlighted.
Jim
Modified Script
-- Start of Script --
tell application "Microsoft Entourage"
try
set theMessages to current messages
on error
beep
return -99
end try
set oldTIDs to AppleScript's text item delimiters
set summaryList to {"From" & tab & "Date/Time" & tab & "Subject" & tab & "Recipients" & tab & "Attachments"}
repeat with aMessage in theMessages
tell aMessage
-- set theSender to "\"" & display name of sender & "\" <" & address of sender & ">"
set theSender to display name of sender
if length of theSender = 0 then
set theSender to "<" & address of sender & ">"
end if
--
-- set timeSent to time sent as string
set mytime to time sent
set timeSent to day of (mytime) as string
set timeSent to timeSent & " " & month of mytime
set timeSent to timeSent & " " & (year of mytime as string)
set timeSent to timeSent & " " & time string of mytime
--
set theSub to subject
if attachments is not {} then
set AppleScript's text item delimiters to {", "}
set theAttachments to (name of every attachment) as string
else
set theAttachments to ""
end if
set theRecips to every recipient
set recipList to {}
if length of theRecips > 3 then
set extraRecips to (count theRecips) - 3
repeat with x from 1 to 3
-- copy "\"" & display name of address of item x of theRecips & "\" <" & address of address of item x of theRecips & ">" to end of recipList
set recipname to display name of address of item x of theRecips
if length of recipname = 0 then
set recipname to "<" & address of address of item x of theRecips & ">"
end if
copy recipname to end of recipList
--
end repeat
set theRecips to recipList
copy "+ " & extraRecips & " additional recipients" to end of theRecips
else
repeat with x from 1 to length of theRecips
-- copy "\"" & display name of address of item x of theRecips & "\" <" & address of address of item x of theRecips & ">" to end of recipList
set recipname to display name of address of item x of theRecips
if length of recipname = 0 then
set recipname to "<" & address of address of item x of theRecips & ">"
end if
copy recipname to end of recipList
--
end repeat
set theRecips to recipList
end if
set AppleScript's text item delimiters to {", "}
set theRecips to theRecips as string
set AppleScript's text item delimiters to {tab}
copy {theSender, timeSent, theSub, theRecips, theAttachments} as string to end of summaryList
end tell
end repeat
end tell
set AppleScript's text item delimiters to return
set the clipboard to summaryList as string
set AppleScript's text item delimiters to oldTIDs
-- End of Script --
