I'm trying to use a script called Merge Contacts, which allows you to
highlight two contacts, and combine them.

However, I'm getting this error message: "Can't get <<class plSy>> of
contact ID 3527.

Here's the script, below. If anyone knows the fix for this, please pass it
on. Thanks. 

Scott


tell application "Microsoft Entourage"
    -- basic error check, do we have two contacts selected?
    set Sel to the selection
    set Stype to class of (item 1 of Sel)
    count Sel
    if the result is not 2 or Stype is not contact then
        error "You must select two and only two contacts to merge."
        return
    end if
    
    -- preserve the me contact, if one of the selected contacts is the me
contact
    -- else try to save the last received or sent information
    if (me contact is (item 1 of Sel)) then
        set contact1 to item 1 of Sel
        set contact2 to item 2 of Sel
    else if (me contact is (item 2 of Sel)) then
        set contact2 to item 1 of Sel
        set contact1 to item 2 of Sel
    else if (last received date of (item 1 of Sel) ‚ date "Friday, January
1, 1904 12:00:00 AM") or ¬
        (last sent date of (item 1 of Sel) ‚ date "Friday, January 1, 1904
12:00:00 AM") then
        set contact1 to item 1 of Sel
        set contact2 to item 2 of Sel
    else
        set contact2 to item 1 of Sel
        set contact1 to item 2 of Sel
    end if
    
    -- try to prevent unfortunate accidents by verifying the merge if the
names are different
    set mergecontacts to true
    if (first name of contact1 ‚ first name of contact2) or ¬
        (last name of contact1 ‚ last name of contact2) then
        display dialog "Do you really want to merge the contacts " & ¬
            first name of contact1 & " " & last name of contact1 & " and " &
¬
            first name of contact2 & " " & last name of contact2 & "?" with
icon 2
        if button returned of result ‚ "OK" then set mergecontacts to false
    end if
    
    if mergecontacts = true then
        --first name
        set field_name to "First name"
        set a to first name of contact1
        set b to first name of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set first name of contact1 to c
        
        set field_name to "First name furigana"
        set a to first name furigana of contact1
        set b to first name furigana of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set first name furigana of contact1 to c
        --Last name
        set field_name to "Last name"
        set a to last name of contact1
        set b to last name of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set last name of contact1 to c
        
        set field_name to "Last name furigana"
        set a to last name furigana of contact1
        set b to last name furigana of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set last name furigana of contact1 to c
        -- title
        set field_name to "Title"
        set a to title of contact1
        set b to title of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set title of contact1 to c
        -- nickname
        set field_name to "Nickname"
        set a to nickname of contact1
        set b to nickname of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set nickname of contact1 to c
        -- suffix
        set field_name to "Suffix"
        set a to suffix of contact1
        set b to suffix of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set suffix of contact1 to c
        -- job title
        set field_name to "Job title"
        set a to job title of contact1
        set b to job title of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set job title of contact1 to c
        -- company
        set field_name to "Company"
        set a to company of contact1
        set b to company of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set company of contact1 to c
        
        set field_name to "Company furigana"
        set a to company furigana of contact1
        set b to company furigana of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set company furigana of contact1 to c
        -- department
        set field_name to "Department"
        set a to department of contact1
        set b to department of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set department of contact1 to c
        -- description
        set field_name to "Description"
        set a to description of contact1
        set b to description of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set description of contact1 to c
        -- home web page
        set field_name to "Home web page"
        set a to home web page of contact1
        set b to home web page of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set home web page of contact1 to c
        -- business web page
        set field_name to "Business web page"
        set a to business web page of contact1
        set b to business web page of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set business web page of contact1 to c
        
        -- E-mail addresses (a list)
        set field_name to "E-mail addresses (a list)"
        set a_mail to every email address of contact1
        set b_mail to every email address of contact2
        repeat with oneAddr in a_mail
            if oneAddr is not in b_mail then copy oneAddr to end of b_mail
        end repeat
        set a_count to count (a_mail)
        repeat with i from 1 to (count b_mail)
            if i ¾ a_count then
                set contents of email address i of contact1 to (item i of
b_mail)
            else
                make new email address of contact1 with data (item i of
b_mail)
            end if
        end repeat
        -- Categories (a list of references)
        set field_name to "Categories (a list)"
        set a_cat to category of contact1
        set b_cat to category of contact2
        set b_name to {}
        repeat with i from 1 to (count b_cat)
            copy name of item i of b_cat to end of b_name
        end repeat
        repeat with oneAddr in a_cat
            if name of oneAddr is not in b_name then copy oneAddr to end of
b_cat
        end repeat
        if b_cat ‚ a_cat then set category of contact1 to b_cat
        -- Home address fields
        set field_name to "Home street address"
        set a to street address of home address of contact1
        set b to street address of home address of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set street address of home address of contact1 to c
        set field_name to "Home city"
        set a to city of home address of contact1
        set b to city of home address of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set city of home address of contact1 to c
        set field_name to "Home state"
        set a to state of home address of contact1
        set b to state of home address of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set state of home address of contact1 to c
        set field_name to "Home zip"
        set a to zip of home address of contact1
        set b to zip of home address of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set zip of home address of contact1 to c
        set field_name to "Home country"
        set a to country of home address of contact1
        set b to country of home address of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set country of home address of contact1 to c
        -- Business address fields
        set field_name to "Business street address"
        set a to street address of business address of contact1
        set b to street address of business address of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set street address of business address of contact1 to
c
        set field_name to "Business city"
        set a to city of business address of contact1
        set b to city of business address of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set city of business address of contact1 to c
        set field_name to "Business state"
        set a to state of business address of contact1
        set b to state of business address of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set state of business address of contact1 to c
        set field_name to "Business zip"
        set a to zip of business address of contact1
        set b to zip of business address of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set zip of business address of contact1 to c
        set field_name to "Business country"
        set a to country of business address of contact1
        set b to country of business address of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set country of business address of contact1 to c
        -- Birthday
        set field_name to "Birthday"
        set a to birthday of contact1
        set b to birthday of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set birthday of contact1 to c
        -- age
        set field_name to "Age"
        set a to age of contact1
        set b to age of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set age of contact1 to c
        -- home phone number
        set field_name to "Home phone number"
        set a to home phone number of contact1
        set b to home phone number of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set home phone number of contact1 to c
        -- other home phone number
        set field_name to "Other home phone number"
        set a to other home phone number of contact1
        set b to other home phone number of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set other home phone number of contact1 to c
        -- home fax phone number
        set field_name to "Home fax phone number"
        set a to home fax phone number of contact1
        set b to home fax phone number of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set home fax phone number of contact1 to c
        -- business phone number
        set field_name to "Business phone number"
        set a to business phone number of contact1
        set b to business phone number of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set business phone number of contact1 to c
        -- other business phone number
        set field_name to "Other business phone number"
        set a to other business phone number of contact1
        set b to other business phone number of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set other business phone number of contact1 to c
        -- business fax phone number
        set field_name to "Business fax phone number"
        set a to business fax phone number of contact1
        set b to business fax phone number of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set business fax phone number of contact1 to c
        -- main phone number
        set field_name to "Main phone number"
        set a to main phone number of contact1
        set b to main phone number of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set main phone number of contact1 to c
        -- pager phone number
        set field_name to "Pager phone number"
        set a to pager phone number of contact1
        set b to pager phone number of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set pager phone number of contact1 to c
        -- mobile phone number
        set field_name to "Mobile phone number"
        set a to mobile phone number of contact1
        set b to mobile phone number of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set mobile phone number of contact1 to c
        -- assistant phone number
        set field_name to "Assistant phone number"
        set a to assistant phone number of contact1
        set b to assistant phone number of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set assistant phone number of contact1 to c
        --    custom phone number one
        set field_name to "Custom phone number one"
        set a to custom phone number one of contact1
        set b to custom phone number one of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set custom phone number one of contact1 to c
        --    custom phone number two
        set field_name to "Custom phone number two"
        set a to custom phone number two of contact1
        set b to custom phone number two of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set custom phone number two of contact1 to c
        --    custom phone number three
        set field_name to "Custom phone number three"
        set a to custom phone number three of contact1
        set b to custom phone number three of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set custom phone number three of contact1 to c
        --    custom phone number four
        set field_name to "Custom phone number four"
        set a to custom phone number four of contact1
        set b to custom phone number four of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set custom phone number four of contact1 to c
        -- custom field one
        set field_name to "Custom field one"
        set a to custom field one of contact1
        set b to custom field one of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set custom field one of contact1 to c
        -- custom field two
        set field_name to "Custom field two"
        set a to custom field two of contact1
        set b to custom field two of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set custom field two of contact1 to c
        -- custom field three
        set field_name to "Custom field three"
        set a to custom field three of contact1
        set b to custom field three of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set custom field three of contact1 to c
        -- custom field four
        set field_name to "Custom field four"
        set a to custom field four of contact1
        set b to custom field four of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set custom field four of contact1 to c
        -- custom field five
        set field_name to "Custom field five"
        set a to custom field five of contact1
        set b to custom field five of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set custom field five of contact1 to c
        -- custom field six
        set field_name to "Custom field six"
        set a to custom field six of contact1
        set b to custom field six of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set custom field six of contact1 to c
        -- custom field seven
        set field_name to "Custom field seven"
        set a to custom field seven of contact1
        set b to custom field seven of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set custom field seven of contact1 to c
        -- custom field eight
        set field_name to "Custom field eight"
        set a to custom field eight of contact1
        set b to custom field eight of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set custom field eight of contact1 to c
        -- astrology sign
        set field_name to "Astrology sign"
        set a to astrology sign of contact1
        set b to astrology sign of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set astrology sign of contact1 to c
        -- spouse
        set field_name to "Spouse"
        set a to spouse of contact1
        set b to spouse of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set spouse of contact1 to c
        set field_name to "Spouse furigana"
        set a to spouse furigana of contact1
        set b to spouse furigana of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set spouse furigana of contact1 to c
        -- interests
        set field_name to "Interests"
        set a to interests of contact1
        set b to interests of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set interests of contact1 to c
        -- blood type
        set field_name to "Blood type"
        set a to blood type of contact1
        set b to blood type of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set blood type of contact1 to c
        -- custom date field one
        set field_name to "Custom date field one"
        set a to custom date field one of contact1
        set b to custom date field one of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set custom date field one of contact1 to c
        -- custom date field two
        set field_name to "Custom date field two"
        set a to custom date field two of contact1
        set b to custom date field two of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set custom date field two of contact1 to c
        -- anniversary
        set field_name to "Anniversary"
        set a to anniversary of contact1
        set b to anniversary of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set anniversary of contact1 to c
        -- sync with palm boolean
        set field_name to "Sync with palm"
        set a to «class plSy» of contact1
        set b to «class plSy» of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set «class plSy» of contact1 to c
        -- children (a list of strings)
        set field_name to "Children's names"
        set a_children to children of contact1
        set b_children to children of contact2
        repeat with child in a_children
            if b_children does not contain child then set b_children to
(child as list) & b_children
        end repeat
        set children of contact1 to b_children
        
        -- Japanese format
        set field_name to "Japanese format"
        set a to Japanese format of contact1
        set b to Japanese format of contact2
        set c to my mergefields(a, b, field_name)
        if c ‚ a then set Japanese format of contact1 to c
        --    say "Merge complete."
        set flagged of contact1 to false
        set flagged of contact2 to true
        beep
    end if
end tell

on mergefields(a, b, field_name)
    if a ‚ b then
        if a = "" then
            return b
        else if b = "" then
            return a
        else
            if length of (a as string) > 100 then
                set a_brief to text 1 thru 100 of a as string
            else
                set a_brief to a
            end if
            if length of (b as string) > 100 then
                set b_brief to text 1 thru 100 of b as string
            else
                set b_brief to b
            end if
            display dialog "For field " & field_name & ¬
                ", Choose A, B, or More Choices to merge or enter new data"
& return ¬
                & "A: " & a_brief & return & "B: " & b_brief & return ¬
                buttons {"A", "B", "More Choices"} default button 1
            set pressed to button returned of result
            if pressed is "A" then return a
            if pressed is "B" then return b
            display dialog "For field " & field_name & ¬
                ", Choose Merge to merge the fields, or Enter New Data" &
return ¬
                & "A: " & a_brief & return & "B: " & b_brief & return & "New
Data:" & return ¬
                buttons {"Merge", "Enter New Data"} default button 1 ¬
                default answer ""
            set {pressed, ans} to {button returned of result, text returned
of result}
            if pressed is "Merge" then return a & " " & b
            -- New data
            return ans
        end if
    else
        return a
    end if
end mergefields


--
To unsubscribe:
<mailto:[EMAIL PROTECTED]>
archives:
<http://www.mail-archive.com/entourage-talk%40lists.letterrip.com/>
old-archive:
<http://www.mail-archive.com/entourage-talk%40lists.boingo.com/>

Reply via email to