Title: Script to fix first/last names of contacts
Here is a short script I wrote for myself. After doing a bunch of importing contacts, I noticed that the first and last name fields of a lot of contacts were mixed up when I listed a couple, or someone with initials. The first word got put into first name and everything else in last name, for example:

"John", "A. Doe"
"Pam", "& Peter Patterson"

I wrote this script to move the info from the last field into the first, so that the above would become:

"John A", "Doe"
"Pam & Peter", "Patterson"

This way, "Doe" and "Patterson" sort properly in the alphabetic list. It isn't a big deal, but it was important to me.

The script works on a very simple principle. If there is a blank space in "last name" it displays the two fields to you and asks if you want to "Merge","Leave Alone", or "Cancel". The merge operation will function as above. Note that any punctuation around initials will disappear the way the script works. "Leave Alone" does just that. "Cancel" will quit the script at that point without modifying the record being displayed.

I ran this on 1450 contacts with about thirty or forty records singled out. It ran fairly fast. The script will beep once every fifty contacts just to give you some idea of progress.

tell application "Microsoft Entourage"
    set allC to every contact
    set cnt to count allC
    set od to AppleScript's text item delimiters
    set AppleScript's text item delimiters to " "
    repeat with i from 1 to cnt
        set aC to item i of allC
        if ((i mod 50) = 0) then beep
        if last name of aC contains " " then
            display dialog "1st:" & first name of aC & return ¬
                & "2nd:" & last name of aC & return ¬
                buttons {"Merge", "Leave Alone", "Cancel"} default button "Merge"
            set toDo to button returned of result
            if toDo is "Cancel" then
                set AppleScript's text item delimiters to od
                return
            end if
            if toDo is "Merge" then
                set n1 to first name of aC
                set n2 to last name of aC
                set toMove to (words 1 thru -2 of n2) as text
                set n1 to n1 & " " & toMove
                set n2 to word -1 of n2
                set first name of aC to n1
                set last name of aC to n2
            end if
        end if
    end repeat
    set AppleScript's text item delimiters to od
end tell
--
Peace,
Allen Watson <[EMAIL PROTECTED]> XNS name: =Allen Watson
A Mac family since 1984 <http://home.earthlink.net/~allenwatson/>
Applescripts for Outlook Express and Entourage: <http://homepage.mac.com/allenwatson/>

Reply via email to