Sorry for the long post....but I didn't know any other way to do this...How do I add a closing tag to the following script? I want to close the contact window after it is added to my address book. I have about 5000 addresses to add, so I can't have outlook open all 5000 windows.
global dontDialogMeMan
set dontDialogMeMan to false
tell application "Script Editor"
activate
-- figure out what messages to process
set theMessages to «class CMgs»
repeat with theMsg in theMessages
my ProcessMsg(theMsg)
end repeat
end tell
-- process the messages
on ProcessMsg(theMsg)
tell application "Script Editor"
--check the to field (in case this is a mailing list)
--get the recipient info
set recipientAddress to the «class addr» of «class rcpt» 1 of theMsg
set recipientdisplayName to the «class dspn» of recipientAddress
set recipientEmailAddress to the «class addr» of recipientAddress
my updateContact(recipientdisplayName, recipientEmailAddress, true)
--get the sender info
set SenderdisplayName to the «class dspn» of the «class sndr» of theMsg
set SenderEmailAddress to the «class addr» of the «class sndr» of theMsg
my updateContact(SenderdisplayName, SenderEmailAddress, true)
end tell
end ProcessMsg
on updateContact(thedisplayName, theEmailAddress, useDialog)
global dontDialogMeMan
tell application "Script Editor"
if thedisplayName is "" then --no display name
set matchedContacts to {}
try
set matchedContacts to every «class cAbE» whose contents of «class cEmA» 1 is theEmailAddress --just check email address 1
end try
if number of items in matchedContacts is 0 then
open (make new «class cAbE» with properties {«class addr»:theEmailAddress})
set dontDialogMeMan to true
else
if useDialog and not dontDialogMeMan then
set theResponse to display dialog "The address " & (theEmailAddress as string) & ¬
" is already in the address book: Do you want to edit this contact?" buttons {"Yes", "No"} default button 2 with icon 2 giving up after 20
if ((gave up of theResponse) or (button returned of theResponse is "No")) then
-- do nothing
else
repeat with x in matchedContacts
open x
end repeat
end if
end if
end if
else
if «class cAbE» thedisplayName exists then
set theContact to «class cAbE» thedisplayName
if class of theContact is list then
set theContact to item 1 of theContact
end if
-- see if email address already exists anywhere in this contact
set emailAddress to every «class cEmA» of theContact whose contents is (contents of theEmailAddress)
if number of items of emailAddress is 0 then
-- add email address
make new «class cEmA» at theContact with properties {contents:theEmailAddress}
open theContact
end if
if useDialog and not dontDialogMeMan then
set theResponse to display dialog "Contact: " & thedisplayName & " with email address: " & contents of theEmailAddress & ¬
" already exists. Do you want to edit it?" buttons {"Yes", "No"} default button 2 with icon 2 giving up after 20
if ((gave up of theResponse) or (button returned of theResponse is "No")) then
--do nothing
else
open theContact
end if
end if
else
open (make new «class cAbE» with properties {«class dspn»:thedisplayName, «class addr»:theEmailAddress})
end if
end if
end tell
end updateContact