Title: Re: script ideas [LONG SCRIPT]
On 10/19/00 6:09 AM, "Rick Johnson" <[EMAIL PROTECTED]> wrote:

> 3) Put email address in email address list: Entourage imported from my
> Excel database the home email addresses into the home phone list of
> Entourage. Can a script move it, in all 1200 records, to the email tab
> where it belongs?

Here's the script. I prefer to make it as applicable to as many people as possible, so it lets you tell it which phone field(s) you have the email addresses in. It will take some time. If you do not have this problem in (almost) every contact, but just some of them, try "some" when asked. It will be faster. But I know from experience that when you have several thousand total contacts, this (getting "every contact whose" anything) will sometimes cause a memory overload and you get a memory error. Suggestions:

If you have a huge address base, which i think you must, more than those 1200, increase memory of entourage to 20-30MB or so before running the script. (It's a good idea for you to have at least double the default anyway if you have such a large database.) You can reduce it later.

If you get a memory error with "Some", increase memory more, or run the script with "All". You will not likely have a memory error then (unless it overflows the system's memory stack), but it will be VERY slow. It's likely to be slow in any case.

Some good news: minimal testing is showing that when the home phone number is selected as the field (like yours), then the email address ends up as "Home", even where there's no Work email address. It will be interesting to see if that's consistent.



-----------------------FIX EMAIL PHONE FIELDS--------------------------



on run
    
    tell application "Microsoft Entourage"
        
        set custList to address book 1's {custom phone number one name, custom phone number two name, custom phone number three name, custom phone number four name}
        
        repeat with i from 1 to 4
            set x to item i of custList
            if x ends with ":" then set x to text 1 thru -2 of x
            set item i of custList to x
        end repeat
        
        set {custName1, custName2, custName3, custName4} to custList
        
        
        
        set allFields to {"All Phone Fields", "Home", "Home 2", "Work", "Work 2", "Pager", "Mobile", "Assistant", "Main", custName1, custName2, custName3, custName4}
        set phoneFields to choose from list allFields with prompt "Select one or more phone fields containing email addresses. Use command key for multiple selections." with multiple selections allowed without empty selection allowed
        
        if phoneFields = false then
            set phoneFields to ""
            error number -128
        end if
        
        if "All Phone Fields" is in phoneFields then set phoneFields to allFields
        
        display dialog "If (almost) all your contacts have email addreses in a phone field, click \"All\"." & return & return & "If only a smaller proportion have them, click \"Some\"." & return & return & "If you have a huge Address Book and get a memory error with \"Some\", come back and do \"All\"." buttons {"Cancel", "All", "Some"} with icon 1
        
        if button returned of result = "Cancel" then
            error number -128
        else
            set howMany to button returned of result
        end if
        
        if howMany = "All" then set allContactsList to every contact
        
        if "Home" is in phoneFields then
            if howMany = "Some" then
                set homeList to every contact whose home phone number contains "@"
            else
                set homeList to allContactsList -- doesn't stress memory, but takes longer
            end if
            
            repeat with theContact in homeList
                tell theContact
                    set theAddress to home phone number
                    set theName to name
                    make new email address at theContact with properties {contents:theAddress}
                    set home phone number to ""
                end tell
            end repeat
            
        end if
        
        if "Home 2" is in phoneFields then
            if howMany = "Some" then
                set otherHomeList to every contact whose other home phone number contains "@"
            else
                set otherHomeList to allContactsList -- doesn't stress memory, but takes longer
            end if
            repeat with theContact in otherHomeList
                tell theContact
                    set theAddress to other home phone number
                    set theName to name
                    make new email address at theContact with properties {contents:theAddress}
                    set other home phone number to ""
                end tell
            end repeat
        end if
        
        if "Work" is in phoneFields then
            if howMany = "Some" then
                set workList to every contact whose business phone number contains "@"
            else
                set workList to allContactsList -- doesn't stress memory, but takes longer
            end if
            repeat with theContact in workList
                tell theContact
                    set theAddress to business phone number
                    set theName to name
                    make new email address at theContact with properties {contents:theAddress}
                    set business phone number to ""
                end tell
            end repeat
        end if
        
        if "Work 2" is in phoneFields then
            if howMany = "Some" then
                set otherWorkList to every contact whose other business phone number contains "@"
            else
                set otherWorkList to allContactsList -- doesn't stress memory, but takes longer
            end if
            
            repeat with theContact in otherWorkList
                tell theContact
                    set theAddress to other business phone number
                    set theName to name
                    make new email address at theContact with properties {contents:theAddress}
                    set other business phone number to ""
                end tell
            end repeat
        end if
        
        if "Pager" is in phoneFields then
            if howMany = "Some" then
                set pagerList to every contact whose pager phone number contains "@"
            else
                set pagerList to allContactsList -- doesn't stress memory, but takes longer
            end if
            
            repeat with theContact in pagerList
                tell theContact
                    set theAddress to pager phone number
                    set theName to name
                    make new email address at theContact with properties {contents:theAddress}
                    set pager phone number to ""
                end tell
            end repeat
        end if
        
        if "Mobile" is in phoneFields then
            if howMany = "Some" then
                set mobileList to every contact whose mobile phone number contains "@"
            else
                set mobileList to allContactsList -- doesn't stress memory, but takes longer
            end if
            repeat with theContact in mobileList
                tell theContact
                    set theAddress to mobile phone number
                    set theName to name
                    make new email address at theContact with properties {contents:theAddress}
                    set mobile phone number to ""
                end tell
            end repeat
        end if
        
        if "Assistant" is in phoneFields then
            if howMany = "Some" then
                set assistantList to every contact whose assistant phone number contains "@"
            else
                set assistantList to allContactsList -- doesn't stress memory, but takes longer
            end if
            repeat with theContact in assistantList
                tell theContact
                    set theAddress to assistant phone number
                    set theName to name
                    make new email address at theContact with properties {contents:theAddress}
                    set assistant phone number to ""
                end tell
            end repeat
        end if
        
        if "Main" is in phoneFields then
            if howMany = "Some" then
                set mainList to every contact whose main phone number contains "@"
            else
                set mainList to allContactsList -- doesn't stress memory, but takes longer
            end if
            repeat with theContact in mainList
                tell theContact
                    set theAddress to main phone number
                    set theName to name
                    make new email address at theContact with properties {contents:theAddress}
                    set main phone number to ""
                end tell
            end repeat
        end if
        
        
        if custName1 is in phoneFields then
            if howMany = "Some" then
                set custom1List to every contact whose custom phone number one contains "@"
            else
                set custom1List to allContactsList -- doesn't stress memory, but takes longer
            end if
            repeat with theContact in custom1List
                tell theContact
                    set theAddress to custom phone number one
                    set theName to name
                    make new email address at theContact with properties {contents:theAddress}
                    set custom phone number one to ""
                end tell
            end repeat
        end if
        
        if custName2 is in phoneFields then
            if howMany = "Some" then
                set custom2List to every contact whose custom phone number two contains "@"
            else
                set custom2List to allContactsList -- doesn't stress memory, but takes longer
            end if
            repeat with theContact in custom2List
                tell theContact
                    set theAddress to custom phone number two
                    set theName to name
                    make new email address at theContact with properties {contents:theAddress}
                    set custom phone number two to ""
                end tell
            end repeat
        end if
        
        if custName3 is in phoneFields then
            if howMany = "Some" then
                set custom3List to every contact whose custom phone number three contains "@"
            else
                set custom3List to allContactsList -- doesn't stress memory, but takes longer
            end if
            repeat with theContact in custom3List
                tell theContact
                    set theAddress to custom phone number three
                    set theName to name
                    make new email address at theContact with properties {contents:theAddress}
                    set custom phone number three to ""
                end tell
            end repeat
        end if
        
        if custName4 is in phoneFields then
            if howMany = "Some" then
                set custom4List to every contact whose custom phone number four contains "@"
            else
                set custom4List to allContactsList -- doesn't stress memory, but takes longer
            end if
            repeat with theContact in custom4List
                tell theContact
                    set theAddress to custom phone number four
                    set theName to name
                    make new email address at theContact with properties {contents:theAddress}
                    set custom phone number four to ""
                end tell
            end repeat
        end if
        
    end tell
    
end run



-------------------end script----------------------














--
Paul Berkowitz

Reply via email to