Address Book Search

Submitted by:J Kamy81

Date added:02 April, 2017

Category:AppleScript

Last name matches the user input and returns their phone and email information

Tags: search , address , book

Code Snippet:

property the_delim : ", "
property search_name : ""

repeat
set search_name to text returned of ¬
(display dialog "What is the name you want to search for:" default answer search_name buttons {"Cancel", "Search"} default button 2 with icon 1)
try
set the_person to (choose from list (my get_info(search_name))) as string
if the_person = "false" then exit repeat
if button returned of ¬
(display dialog the_person buttons {"Copy to Clipboard", "Thanks"} default button 2 with icon 1) ¬
= "Copy to Clipboard" then set the clipboard to the_person
exit repeat
on error
beep
if button returned of ¬
(display dialog ("No matches were found for “" & search_name & ".” Search for a new name?") buttons {"No", "Yes"} default button 2 with icon 2) ¬
= "No" then exit repeat
end try
end repeat

on get_info(the_name)
tell application "Address Book"
set the_data to {}
set the_people to every person whose last name = the_name
repeat with the_person in the_people
tell the_person
set this_data to name
repeat with this_email in every email
set this_data to this_data & the_delim & (label of this_email) & " email: " & (value of this_email)
end repeat
repeat with this_phone in every phone
set this_data to this_data & the_delim & (label of this_phone) & " number: " & (value of this_phone)
end repeat
end tell
set end of the_data to this_data
end repeat
end tell
return the_data
end get_info
 
 

Comments