lørdag, januar 26, 2008

Gengangere

Nej det skal ikke handle om spøgelser og gespenster; men om dublerede indgange i Adressebogen. Det er noget rod, og opstår desværre nemt, hvis man synkroniserer sin Adressebog på Macen med sin mobiltelefon, en onlinetjeneste og måske en anden Mac også.

Det er selvfølgelig muligt at rydde op i hånden; men det er da lidt sjovere at finde et script til at gøre det for én, ikk'?

Lidt søgning på problemet viste, at jeg ikke var den eneste, og på MacOSXHints fandt jeg en løsning, der fungerer fint på min OS X 10.4.11.

HUSK at tage en backup af din Adressebog, inden du begynder - bare for en sikkerheds skyld!

--
-- A script to look for duplicate cards in the Address Book
-- It looks for identical names, companies and emails
-- As distributed it requires identical emails,
-- or identical first,middle and last names plus company name to be considered identical
-- Simply comment out the code associated with an attribute to remove it from consideration
-- If multiple emails are associated with a card then the first one is considered canonical.
--
-- The script is a modification of the script authored by Safar
-- http://www.macosxhints.com/users.php?mode=profile&uid=1000517 and http://www.etincelle.org/
-- I have kept the French variable names, and added my English ones (ONE world!)
--
-- Version 13. SM 20070714
--
property duplicate_group_name : "Doubles"
property automatic_move : true -- the default and automatic action is to move the possible duplicates to the group with the name given by duplicate_group_name

display dialog "The name of the group to collect possible duplicates" default answer duplicate_group_name
set duplicate_group_name to text returned of result

display dialog "Should identified duplicates be moved to " & duplicate_group_name & " automatically?" buttons ["yes", "no"] default button 2
if (button returned of result is "yes") then
set automatic_move to true
else
set automatic_move to false
end if
set liste to {}
set email_liste to {}
set avirer to {}
tell application "Address Book"
with timeout of 3200 seconds
set code to ""
if not (duplicate_group_name is in name of every group) then
set duplicate_group to make new group with properties {name:duplicate_group_name}
else
set duplicate_group to every group whose name is duplicate_group_name
end if
repeat with this_person in every person -- of group "PossibleDuplicates"
-- Comment out the components you don't want to test on
set full_name to ""

set first_name to first name of this_person as string
if first_name = "missing value" then set first_name to ""
set full_name to full_name & first_name

set middle_name to middle name of this_person as string
if middle_name = "missing value" then set middle_name to ""
set full_name to full_name & middle_name

set last_name to last name of this_person as string
if last_name = "missing value" then set last_name to ""
set full_name to full_name & last_name

set this_email_list to properties of emails of this_person
try
set this_email to value of item 1 of this_email_list
on error
set this_email to ""
end try
set full_name to full_name & this_email

set this_company to company of this_person as string
if this_company = "false" then set this_company to ""
set full_name to full_name & this_company

if (full_name > "" and not (full_name = "true")) then
if full_name is in liste then
if automatic_move = false then
-- check the user's preference
display dialog ("Possible duplicate (name): " & first_name & " " & middle_name & " " & last_name & " " & this_company & " " & this_email) buttons ["ignore", "move to " & duplicate_group_name, "Cancel"] default button 2
if button returned of result is ("move to " & duplicate_group_name) then
set lid to this_person's id
set avirer to avirer & lid
end if
else
set lid to this_person's id
set avirer to avirer & lid
end if
else
set liste to liste & full_name
end if
else if (this_email > "") then
if this_email is in email_liste then
if automatic_move = false then
-- check the user's preference
display dialog ("Possible duplicate (email): " & first_name & " " & middle_name & " " & last_name & " " & this_company & " " & this_email) buttons ["ignore", "move to " & duplicate_group_name, "Cancel"] default button 2
if button returned of result is ("move to " & duplicate_group_name) then
set lid to this_person's id
set avirer to avirer & lid
end if
else
set lid to this_person's id
set avirer to avirer & lid
end if
else
set email_liste to email_liste & this_email
end if
end if

end repeat

repeat with une in avirer
set bla to person id une
-- set lenom to name of bla
add bla to group duplicate_group_name
end repeat
save addressbook
end timeout
end tell



Sæt ovenstående kode ind i ScriptEditor, kompiler og kør, så beder scriptet om et navn til den gruppe, som dubletter skal flyttes til, og du spørges evt for hver enkelt, om de skal flyttes til gruppen.

Så er det bagefter nemt at gennemse den nye gruppe for, om de pågældende rent faktisk skal slettes eller indarbejdes i nogle andre kort.

Der findes andre scripts, som også tilbyder lignende funktion; men en del af dem, fjerne blot dubletterne, og det er ikke så sjovt, hvis de kun har checket på navn f.eks. og man gerne ville have oplysningerne kombineret.
Adressebogs indbyggede "Find dubletter" er mildest talt lidt fjollet, da den ikke oplyser om, hvilke oplysninger på hvilke kort, den har tænkt sig at gøre noget ved ;(

0 kommentarer:

Blog Widget by LinkWithin