Title: Script, Find Contact Plus (Long)
Several people have posted scripts that attempt to work around the bug in opening contacts that causes a long hesitation (proportional to the size of your Address Book--mine is 1650+ contacts) when you try to open a contact simply by clicking on it. There is also a considerable delay in using the filter in the Address Book. There are known problems here that are being addressed for the next release, so any such attempt is at best an interim measure.

I have not been satisfied with the scripts I've seen so far. So I set out to develop my own, and I offer the result to you all. This script is fastest when you provide it with the most information: a full name, or a complete E-mail address. In those cases it is almost instant. Here is the "Readme", followed by the script. I'll be posting this on my scripting web site some time tomorrow.

Find Contact Plus -- by Allen Watson <[EMAIL PROTECTED]>
11/9/00

This script for Microsoft Entourage will rapidly locate a contact record, or multiple records, by full name, last name, or E-mail address. When prompted, enter the name  or address you are searching for. The action taken by the script depends on your input.

1. An E-mail address, script will instantly locate and open the first contact with that address.

2. A complete contact name, e.g., "Allen Watson", script will instantly locate and open the first contact matching that name exactly. If there is no exact match, it tries for an inexact match, first name containing the first name you gave, last name containing the last name you gave. Thus, typing "Ben Watson" would locate a record for "Ben & Polly Watson". In the latter case, all matching records will be opened. Note: Typing a company name or nickname will also result in an instant match, but the nickname must be the full nickname. If there is no exact match, the inexact match is done only on the first and last name and company fields.

3. If you type a single last name, e.g., "Watson", script will locate all records with this last name (this takes a bit longer), or company or nickname. It will then offer you two choices:

a. Make a new group called "Temp" containing these contacts. This is a great way to quickly scan the list and find a particular contact you are looking for; double-clicking the name in the group window will open that contact. Later searches will replace the contents of the "Temp" group with the new search results, so if you want to save the result, just rename the group to something else.

b. Attempt to select all the matching contact records in the Address Book. The scripting control of the Address Book is imperfect. For instance, I can't tell whether you have the focus set in the filter box, or the address list. Therefore, I attempt to clear the filter by typing a space (which requires the osax "Sändi's Additions"). Sometimes this option works fine, sometimes it does not. The best results will come if you open the Address Book before running the script and make sure the filter is cleared so that all contacts display.

Fastest results come from typing an E-mail address or a complete name.

----Start Script ----
--- Find Contact Plus\csC ---
--- The above suffix will enable the shortcut Control-Shift-C to launch this script

set theName to text returned of (display dialog "Enter name or E-mail address to find" default answer "")
tell application "Microsoft Entourage"
    activate
    set cnt to count words of theName
    set c to ""
    if theName contains "@" then -- It's an E-mail address
        set cs to find theName
        set c to item 1 of cs
        open c
    else if cnt > 1 then -- Must be full name
        try
            set c to contact theName
            open c
        on error
            set c to ""
        end try
        if c = "" then
            try
                set n1 to word 1 of theName
                set n2 to last word of theName
                try
                    say "Looking for " & theName
                end try
                set cs to contacts whose ((first name contains n1 and last name contains n2) or (company contains theName))
                repeat with c in cs
                    open c
                end repeat
                if (count cs) = 0 then error 1
            on error
                display dialog "Can't find contact named \"" & theName & "\"" with icon 3 buttons {"OK"} default button 1
            end try
        end if
    else -- Last name only, select matches
        -- First, try to get an exact match on just the one word; might be nickname
        set c to ""
        try
            say "looking for " & theName & "." using "Kathy"
        end try
        open address book 1
        set cs to every contact whose (last name contains theName or first name contains theName)
        if (count cs) = 0 then
            try
                try
                    say "Just a little longer please!" using "Kathy"
                end try
                set cs to contacts whose (nickname is theName or company contains theName)
                if (count cs) > 0 then
                    repeat with c in cs
                        open c
                    end repeat
                else
                    display dialog "No contacts matched " & theName with icon 3
                    return
                end if
            end try
        end if
        -- Do they want me to select the contacts, or form a Temp group?
        if (count cs) > 1 then
            display dialog "Do you wish to put the found contacts in a temporary Group (\"Temp\"), or just select them in the Address Book?" buttons {"Temp Group", "Select in Address Book"} default button 1
            set doGroup to (button returned of result is "Temp Group")
            if doGroup then
                --Use empty group named "Temp"
                try
                    set theGroup to group "Temp"
                on error
                    set theGroup to make new group with properties {name:"Temp"}
                end try
                set gEnt to group entries of theGroup
                if (count of gEnt) > 0 then
                    if (count of gEnt) > 0 then
                        repeat with i from (count gEnt) to 1 by -1
                            delete item i of gEnt
                        end repeat
                    end if
                end if
                set theEntries to {}
                repeat with c in cs
                    make new group entry of theGroup with properties {content:c}
                end repeat
                open theGroup
            else
                -- The following clears the filter so all contacts are visible; requires Sändi's Additions
                open address book 1
                try
                    TypeText tab
                    TypeText " "
                    TypeText tab
                    TypeText " "
                    --                display dialog "If names desired are not visible, tab to the contact list and type the name."
                on error
                    display dialog ¬
                        "Last name lookup will fail if all contacts are not visible." & return & ¬
                        "All matching contacts have been selected, if visible." with icon 2
                end try
                set selection to cs
            end if
        else
            set x to item 1 of cs
            open x
        end if
    end if
end tell
--- End of Script ---
--
Peace be with you!
Allen <[EMAIL PROTECTED]> XNS Name: =Allen Watson
My web page: <http://home.earthlink.net/~allenwatson/>

Reply via email to