Re: Outlook Express script debugging
Re: Outlook Express script debugging
- Subject: Re: Outlook Express script debugging
- From: Paul Berkowitz <email@hidden>
- Date: Thu, 10 Jan 2002 20:58:28 -0800
On 1/10/02 3:07 PM, "Jonathan Watterson" <email@hidden> wrote:
>
I'm a rank scripting newbie & I'm attempting to write my first real
>
Applescript to fix my address book in Outlook Express.
>
>
The problem is that when I imported my Yahoo Mail address book into OE last
>
year (using a script I downloaded somewhere), the imported contacts had my
>
Yahoo mail nickname as the first name, a blank last name, and the email
>
address looked like this:
>
>
"Joe Blow"<email@hidden>
>
>
with the old first name, last name, and email address all squished together.
>
>
I've added many more contacts since then, so my address book is now a
>
mixture of Stupid addresses (as described above) and proper ones, with first
>
name, last name, and email addy all in their own fields.
>
>
For months now I've been trying to write an Applescript that will go through
>
the address book, find the Stupid addresses, and correct them. I'm SO close
>
to finally having this licked. I've tested all the parts of this script and
>
everything SHOULD work. But when I run it, it just goes through and ERASES
>
the first name, last name, and email address of each contact!
Jonathan,
Rather than go through your script line by line, here's how I would do it .
I tested just with one contact I "made up", but please let me know if you
have any questions. Remove email line breaks of long lines. AppleScript's
text item delimiters are very useful here. If the "stupid address" is really
"Joe Blow" <email@hidden> (with a space) rather than
"Joe Blow"<email@hidden> (no space) then change that first text item
delimiter from {"<"} to {" <"}.
tell application "Outlook Express"
set allContacts to every contact
repeat with theContact in allContacts
repeat 1 times -- so we can 'try' just the email address
tell theContact
try -- contact may not have an email address
set eAddress to email address 1
on error
exit repeat -- move on to next contact
end try
if eAddress contains "<" then -- no real email address
--contains "<"
set AppleScript's text item delimiters to {"<"}
set dName to text item 1 of eAddress
set eAddress to text 1 thru -2 of text item 2 of
eAddress -- remove ">" -- one line
if dName starts with "\"" then set dName to text 2 thru
-1 of dName -- one line
if dName ends with "\"" then
try -- might be only 1 character "
set dName to text 1 thru -2 of dName
on error
set AppleScript's text item delimiters to {""}
-- reset to default
set dName to ""
set the contact's {first name, last name} to
{"", ""} -- one line
set contents of email address 1 to eAddress
exit repeat -- done
end try
end if -- must be a name for those left here
set AppleScript's text item delimiters to {" "}
set lName to text item -1 of dName
try -- might be no first name
set fName to "" & text items 1 thru -2 of dName --
will have all names except last, separated by a space
on error -- no first name
set fName to ""
end try
set AppleScript's text item delimiters to {""}
set {first name, last name} to {fName, lName}
set contents of email address 1 to eAddress -- even ""
end if -- don't touch others
end tell
end repeat -- 1 times
end repeat
end tell
--
Paul Berkowitz