Das ist nur als Beispiel gedacht, wie so eine Funktion aussehen könnte:
tell application "Contacts"
activate
set my_phone_2_check to text returned of (display dialog "Telefonnummer:" default answer "0")
set allp to people
set phone_numbers to value of every phone of people
repeat with i from 1 to count of phone_numbers
set current_phone_numbers to item i of phone_numbers
if (count of current_phone_numbers) > 0 then
repeat with phone_number_2_check in current_phone_numbers
set phone_number_2_check to phone_number_2_check as text
if phone_number_2_check starts with "+" then
set phone_number_2_check to ("0" & characters 4 through -1 of phone_number_2_check) as text
end if
if phone_number_2_check contains " " then
set phone_number_2_check to my replace_chars(phone_number_2_check, " ", "")
end if
if phone_number_2_check contains "-" then
set phone_number_2_check to my replace_chars(phone_number_2_check, "-", "")
end if
if phone_number_2_check contains "/" then
set phone_number_2_check to my replace_chars(phone_number_2_check, "/", "")
end if
if phone_number_2_check = my_phone_2_check then
set selection to item i of people
error "Die Nummer gibt es schon"
end if
end repeat
end if
end repeat
end tell
to replace_chars(this_text, search_string, replacement_string)
try
if this_text contains the search_string then
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
end if
return this_text
on error msg
error "error on replace_chars" & return & msg
end try
end replace_chars