Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'update - improved results' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
update - improved results
Authored by: macman13 on Jun 09, '03 04:47:39PM

From what I see this returns the name of an email or phone number. Would it not be better to have the search name based and have it return the phone number? Or am I missing something here?

Thanks.
SA

---
\\\"I can do everything on my Mac I used to do on my PC, plus alot more ...\\\"
--Me



[ Reply to This | # ]
Name Lookup
Authored by: Krioni on Jun 09, '03 05:58:38PM
You're right. This version lets you search by partial-name (asking for email or phone), returning a list of all the possible matches and their email/numbers:

#!/bin/sh

if [ $# -ne 2 ]; then
    echo 1>&2 "usage: abook email (or phone) NAME"
    exit 127
fi

scriptcode="
tell application \"Address Book\"
        set idList to get (id) of (every person whose (name contains \"$2\"))
        set valueList to {}
        repeat with oneID in idList
                set oneID to contents of oneID
                set dataList to (get (every $1) of person id oneID)
                repeat with oneValue in dataList
                        copy (name of person id oneID & tab & label of oneValue & tab & value of oneValue) to end of valueList
                end repeat
        end repeat
end tell

set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ASCII character 10}
set lineList to (items of valueList) as string
set AppleScript's text item delimiters to od
return lineList
"

osascript -e "$scriptcode"

exit 0


[ Reply to This | # ]
Name Lookup - caveat
Authored by: Krioni on Jun 09, '03 06:06:13PM

Of course, if you want to search Business records by the person's name, you'll have to search by that, too. For now, it searches by the card's name, which would be the Company name if you've specified the card as a Business.



[ Reply to This | # ]
Name Lookup
Authored by: macman13 on Jun 09, '03 06:40:55PM

Just to rip you off slightly (since I am not a very experienced programmer):

#!/bin/sh

if [ $# -ne 2 ]; then
echo 1>&2 "usage: abook phone YOUR_SEARCH"
exit 127
fi

scriptcode="tell application \"Address Book\"
set thePerson to person \"$2\"
set theProps to the properties of thePerson
set the firstName to the first name of theProps
set the lastName to last name of theProps
set the phnList to the value of every phone of thePerson
set testList to firstName & \" \" & lastName & \" \" & phnList
return testList
end tell"

osascript -e "$scriptcode"

exit 0


This borrows from your script and a safari script to display the phone numbers of the person being named.

ie.
abook phone "Desired Name"

Displays:

Desired Name Phone number

This should do the same as the pb script except that you would still have to add a new name and phone number using the addressbook gui. But this would find a phone number in the terminal from a name.

Any more ideas?

Thanks.
SA

---
\\\"I can do everything on my Mac I used to do on my PC, plus alot more ...\\\"
--Me



[ Reply to This | # ]
hazzah!
Authored by: macubergeek on Jun 09, '03 09:58:09PM

now this works!
many thanks!



[ Reply to This | # ]
Name Lookup
Authored by: macubergeek on Jun 09, '03 08:02:33PM

formatting on this is unuseable...sorry but I'm at a loss for reconciling what I see on the web page with something that will work in shell.



[ Reply to This | # ]
Name Lookup
Authored by: Krioni on Jun 09, '03 08:37:22PM

weird...what web browser are you using? I used the code tag for posting here, as required.



[ Reply to This | # ]