I am writing a script to help me identify all duplicate records in my contacts list which contains 1,500+ contacts.
I have written a portion of the script [as can be seen below] but note that it takes a very long time run on my mid 2012 MBA [i.e. 2 GHz i7 with 8MB of RAM].
Would appreciate code / ideas /suggestions as to how to speed things up…the script is:
tell application "Contacts"
-- Set variables
set myPeople to {} -- List of all contacts details from Contacts
set myPeopleCount to 0 -- Number / count of all contacts from Contacts
set myPeopleList to {} -- List of all contact names and organizations from Contacts
set myPeopleDuplicates to {} -- List of all contact duplicate names and organizations
-- Set / reference every contact
set myPeople to every person
set myPeopleCount to count of myPeople
-- Set / extract individual contact names
repeat with i from 1 to myPeopleCount
set myPeopleIndividualNameCompany to {last name of person i & " " & first name of person i as string, organization of person i}
set end of myPeopleList to myPeopleIndividualNameCompany
end repeat
-- Sort myPeopleIndividualNameCompany to facilitate duplicate comparison
set callSortLocation to "Macintosh HD:Users:JoelC:Documents:Apple:Scripts:Utilities:20141125_script to sort a list of items_specific_complete.scpt" as alias -- Set callSort to load a compiled sorting script
set callSort to (load script callSortLocation)
tell callSort -- Tell callSort to sort myPeopleList
set myPeopleList to simple_sort(myPeopleList)
end tell
end tell
while the sorting script – courtesy of Nigel – which is called is as follows:
-- Handler to sort a list or a list of lists based on the first item in the sublist
on simple_sort(my_list)
set the index_list to {}
set the sorted_list to {}
repeat (the number of items in my_list) times
set the low_item to ""
repeat with i from 1 to (number of items in my_list)
if i is not in the index_list then
set this_item to item i of my_list
if the low_item is "" then
set the low_item to this_item
set the low_item_index to i
else if item 1 of this_item comes before item 1 of the low_item then
set the low_item to this_item
set the low_item_index to i
end if
end if
end repeat
set the end of sorted_list to the low_item
set the end of the index_list to the low_item_index
end repeat
return the sorted_list
end simple_sort
Thanks in advance for the assistance.
Joel