Grabbing all email addresses

S

Scott

About a year ago,
(http://groups.google.com/group/micr...fec7bf9038e/71eb1db1f6714c3d#71eb1db1f6714c3d)
Paul Berkowitz gave a great script here that allowed for highlighting a
group of emails, then running the script where it would add all the
email addresses into a TextEdit doc. Very handy. For some reason, I
can't get it to work now. It gives a blank TextEdit doc.

Also, in that same answer, Paul mentioned a "Add Group" button in the
toolbar. It may be right in front of me, but I can't see that button in
the toolbar, or the Menu. Did it go away in this last rev, or am I just
temporarily blind to it.

Here's the script for Email Addresses to TextEdit:

set newFile to choose file name with prompt "Enter a name and location
for
the text file:" default name "Email addresses.txt" default location
(path to desktop)
tell application "Microsoft Entourage"
set theContacts to (get the selection)
set eAddresses to {}
repeat with theContact in theContacts
try
set end of eAddresses to default email address of theContact
end try
end repeat
set AppleScript's text item delimiters to {","}
set eAddresses to eAddresses as string
set AppleScript's text item delimiters to {""}
end tell

try
close access newFile
end try
set f to open for access newFile with write permission
set eof f to 0
write eAddresses to f
close access f

tell application "TextEdit"
open newFile
activate
end tell
 
P

Paul Berkowitz

No. That script was for selecting (highlighting) a group of CONTACTS in
Entourage's Address Book, not for highlighting emails. See the line:

set theContacts to (get the selection)

It expects that the selection will be contacts. It puts the main operation
(getting g the email address of each selected item) in a 'try' vlovk just in
case you selected a group by mistake. For that reason (and because it was
just a script snippet sent to a newsgroup, without fancy error trapping) if
it selects any non-contact item, it just moves on without an error.

That's why you're getting a blank text file - you didn't select any
contacts. For the same reason, you're not seeing the "Add Group" button in
the toolbar, since that button is in the Address Book, not the Mail area.

So what exactly did you want to do now when selecting email messages - you
sat "add all the email addresses". Add all _which_ email addresses? The
senders'? Include all other recipients, including cc recipients too? Or
what? I'm quite sure someone has done this before, but this will get the
email address of the senders:


set newFile to choose file name with prompt "Enter a name and location for
the text file:" default name "Email addresses.txt" default location (path to
desktop)
tell application "Microsoft Entourage"
set theMsgs to (get current messages)
set eAddresses to {}
repeat with theMsg in theMsgs
try
set end of eAddresses to address of the sender of theMsg
end try
end repeat
set AppleScript's text item delimiters to {", "}
set eAddresses to eAddresses as string
set AppleScript's text item delimiters to {""}
end tell

try
close access newFile
end try
set f to open for access newFile with write permission
set eof f to 0
write eAddresses to f
close access f

tell application "TextEdit"
open newFile
activate
end tell

------------

I added a space between the list items, after the comma. If you want each
one on its own line, change this line:

set AppleScript's text item delimiters to {", "}

to

set AppleScript's text item delimiters to {return}

(or you could make that

{ASCII character 10}
)

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
S

Scott

Thank you, Paul. That script worked perfectly; and thanks for
explaining how to change the script to allow each email address to land
on a separate line in the TextEdit doc. Very handy.

Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top