AppleScript: Adressbuch doppelte Adressen löschen
by hubi on 13/03/2010--remove dupilcated addresses in address-book that occure within ONE person
-- so this script does not replace duplicated persons, but a person's duplicated addresses =)!
-- USE THIS AT YOUR OWN RISK! MAKE A BACKUP BEFORE YOU APPLY IT TO YOUR ADDRESS BOOK!!!
tell application "Address Book"
set deleted_counter to 0
set ll to 0
set my_selections to selection
repeat with my_selection in my_selections
set ll to ll + 1
set current_addresses to {}
if (count of every address of my_selection) > 1 then
repeat with i from 1 to (count of every address of my_selection)
set current_address_string to my delete_space(formatted address of address i of my_selection)
if current_address_string is not in current_addresses then
set current_addresses to current_addresses & current_address_string
else
delete address i of my_selection
set deleted_counter to deleted_counter + 1
end if
end repeat
end if
end repeat
save
end tell
display dialog deleted_counter & " duplicated address-entries have been deleted (" & ll & " persons proccessed)" as text
to delete_space(thestring)
--delete every double-space...
set AppleScript's text item delimiters to " "
set theparts to every text item of thestring
set AppleScript's text item delimiters to ""
set finalparts to {}
repeat with t in theparts
if t as text is not "" then
set finalparts to finalparts & t
end if
end repeat
set AppleScript's text item delimiters to " "
set theparts to finalparts as text
set AppleScript's text item delimiters to ""
--replace spaces at the end of line (if new line comes after it) +++and at beginning
return replace_chars(replace_chars(theparts, "
", "
"), "
", "
")
end delete_space
to replace_chars(this_text, search_string, replacement_string)
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
end replace_chars
No comments yet.