Remove duplicate Address Book emails

I'm trying to write a script that walks through the currently selected Address Book entries, checks for duplicate email addresses, and removes any duplicates that it finds. Here's what I came up with:
<pre>tell application "Address Book"
set the_selection to selection
repeat with this_person in the_selection
set unique_emails to {}
set duplicate_emails to {}
repeat with this_email in every email of this_person
if the value of this_email is in unique_emails then
copy the contents of this_email to the end of duplicate_emails
else
copy the value of this_email to the end of unique_emails
end if
end repeat
repeat with this_email in duplicate_emails
remove this_email from this_person's emails
end repeat
end repeat
end tell</pre>
It seems like this should work, but when I try to run it, I get:
<pre>Address Book got an error: NSReceiversCantHandleCommandScriptError</pre>
I believe the first repeat clause is correct; the error comes in the call to remove. I just can't figure out how to remove the emails listed in duplicate_emails from Address Book. Any suggestions? TIA
PowerBook G4   Mac OS X (10.4.3)  

Yes, that's because of the emails is reduced by one -every time- after the script encounters the second address. On the third encounter the index for this email address is 3, but the actual index of it is 2 -because the second one got deleted, is that make sense?
Yes, I'm just surprised that this is necessary. In some other programming languages (such as Java's collections API), keeping track of indices is not necessary because you can delete an element on the fly and the iterator object will adjust itself accordingly.
Anyway, even though the second repeat loop is not strictly necessary, I'd rather do that than have to deal with index-based loops. The second loop approach is easier to read and understand, I think.
I've posted the final version of the script here: http://vocaro.com/trevor/software/applescript/
Thank you for your help; I appreciate it!
PowerBook G4   Mac OS X (10.4.3)  

Similar Messages

  • Can I use Mackeeper to remove duplicate address book entries?

    On my MacBook using OS 10.7.2 and iTunes 10.5.1, after syncing with iPad2 and iPod Touch I now have 3 and 4 copies of most Address Book entries ON MY MAC BOOK. Can I use Mackeeper to remove duplicates? No option to remove duplicates ever appeared during the sync process.

    I suggest if you have MacKeeper install, that your first move be to uninstall it.
    Here is a script to find duplicates in addressbook
    http://hints.macworld.com/article.php?story=20060322202753429
    Allan

  • How to create a duplicate address book contact?

    This seems so simple yet I cannot determine how to create a new duplicate address book contact. I have a few contacts from the same company and want to change the variable data instead of re entering the data
    I can create a new contact, copy the data of the record I want to duplicate yet when I paste the info into the new record - address book puts everything into one field.
    Why not a duplicate contact command?
    GRRRR

    Rich,
    According to Address Book Help:
    To duplicate an address card:
    Select an address card.
    Choose Edit > Copy, and then choose Edit > Paste.
    Works for me

  • Format address panel in iCal to show Department from the address book. At the moment it is showing 'Job Title' even though that has been removed in Address Book.

    Can anybody help please How do I Format address panel in iCal to show Department from the address book. At the moment it is showing 'Job Title' even though that has been removed in Address Book.

    I have a similar problem. I actually spoke with a Paypal customer Representative a few months back who informed me that they had deleted all of my previous *Hidden* Address but when I just purchased an item today on a online merchant's site that I had never been to before and checked out using their Paypal option, I noticed that my default shipping address was in fact my old address and when I went to change the address to my current address, I noticed all of the old addresses I ever used were still there. I've just spoken with 2 separate paypal representatives who confirmed on their end that all of the old address have been deleted and the only one they have on file is my current address. Can anyone provide me an explanation as to why the old hidden address can still be showing up when I check out on merchant's sites using paypal even after they've seemingly been deleted? The last Representative suggested clearing out my browser's cache, but I don't believe that will resolve my issue. Thank you in advance.

  • DUPLICATE ADDRESS BOOKS... ONE CONTAINS MY APPS

    I have duplicate ADDRESS BOOK folders on my dock. One contains my addresses and the other ADDRESS BOOK folder contains my APPLICATIONS !
    I am missing my APPLICATION FOLDER from the dock. I am a very new IMAC user  .Help please

    One of those is your Applications folder, being displayed as a stack with the top item (Address Book) on top.  Hover the mouse over each one to see the name.  The Applications folder should be the one over near the trash can.  Control-click the Applications folder and choose Folder in the Display As section of the menu that appears.

  • Address book email addresses don't get removed

    When I write a new email, old, deleted email addresses for people still appear as addressee options. Why are they still listed when they have been deleted from the Address Book?

    They are still listed in previous recipients if you have ever sent an email to that address.
    Mail > Menubar > Window > Previous recipients.
    Remove them from there.
    Have fun
    S.

  • How to remove duplicate addresses from address book

    My mac os x address book ( the one after clicking on "WRITE) shows a number of contacts several times and I can't delete the extra ones. When I right click them and hit delete and confirm, they just stay there highlighted.

    I don't have a Mac and I've never used one, so this is somewhat hearsay.
    For a long time, the Mac address book was read-only in Thunderbird. So to manage it, you'd have to access it via whatever tools OSX offers you for this.
    ISTR that in a recent Thunderbird, this might have been fixed, so it is possible that it should now be able to edit and delete OSX address book entries from within Thunderbird.
    Another possibility is that Thunderbird's own address book is corrupted. The usual symptom is that users can edit their Contacts, but when Thunderbird is closed and restarted, it reverts to the state it was in prior to the editing. That is, the changes weren't written to disk. I'm not confident this applies to you, as you don't seem able to make ''any'' changes.
    As a check, if you drag a Contact from the OSX address book to one of Thunderbird's native address books, are you then able to edit the copy? (If you hold down control {command?} while dragging, it should make a copy. If it doesn't have write permission on the OSX address book, it will copy regardless, since it isn't permitted to delete the original in the OSX address book.)
    One way to fix a corrupt address book is to export it and import to a new address book. Ideally you would also close Thunderbird, locate the broken address book file in Thunderbird's profile and delete it.
    There is some advice [http://chrisramsden.vfast.co.uk/11_Thunderbird_Settings_and_the_Profile.html here] about exporting and importing address books.

  • Transfer Outlook Express Address Book & emails from old iMac 333 to iMac G5

    Trying to import my old address book and a collection of emails from Outlook Express 5.0.6 to Mail2.0.2. I've tried everything that Outlook requires and no luck yet. I am reluctant to reload all those names, addresses, etc. into my new iMac G5. Also, I have many emails from my old iMac 333 and need them for my new G5 mail files. Can I read them into Mail 2.0.2 ?
    Thanks for any advice.
    Bob
    iMAC G5 /iBOOK   Mac OS X (10.4.3)   iMAC 333 & iMAC 350

    I was having no success at all when I was trying to import mail data from Outlook Express to Mail on the same office G4 Tower where I just upgraded to Tiger, where all the Apple docu says it is possible...
    Then I realised,
    1. When in X, when importing data from OE, Classic has to be booted, my only and originally OS 9 (installed X on another partition) is to "heavily loaded" with a lot of 3rd party extensions etc, it never loaded completely
    Solution: Install another clean and lean copy of OS 9 somewhere else, then designate this as your Classic, and make sure you only have one copy of OE and one set of your Identities etc in the Document folder
    2. The easier way out is if you have Office X or Office 2004, use Entourage to import everything from OE, then use Mail to import from Entourage.
    Cheers

  • Address Book - email address sorting

    My own entry in my address book has 11 email addresses (I added most of them after they were automatically added to separate entries). The one that appears on the top is the one I want to appear on the bottom. How do I tell Address Book to keep them in a particular order?

    I've never used the TrueSwitch software, but I've never had to. You can export your contacts from Outlook, Outlook Express, etc. into a .csv file and import them directly to your verizon.net account. If you log into your verizon.net account and go to your contacts list there's an Import Contacts button.
    If you need any assistance with that process let me know, I can try to provide a step-by-step for your client.
    As for sorting by name, this functionality does not appear to be available in the "Basic Interface" of Verizon's webmail. Switching to the "Rich Interface" causes the name to be displayed in a Last, First format and sorting by name is an option.
    Hope this helps!
    If a forum member gives an answer you like, give them the Kudos they deserve. If a member gives you the answer to your question, mark the answer as Accepted Solution so others can see the solution to the problem.
    "All knowledge is worth having."

  • De-duplicate address book

    I have synced my Microsoft Outlook address book with my iphone, and all the contacts are duplicated - how can I resolve this?

    I would assume that if you have mobile me or iCloud they are directly saved on either of them automatically. For this to happen , you need to turn on automatic synchronisation in system preference.
    Also , if you want to avoid lost of data one day, I would suggest that you export your contacts as csv. file and email it to yourself in a folder that only you can access. Hope I have answered your question. If so, can you please 'like' the answer to gain credit/points.
    Thank you and good luck

  • Address book email address incorrect in mail.app

    so, in address book i click on the email address of the contact and select "send email" it opens Mail, and auto-completes to the wrong email address.  i've cleared the previous recipients and have also restarted my machine and deleted the contact and started over.  also, when i enter the email address manually, it does not show up as an address book contact (as in, it doesn't create a blue "box" around the name)...  this is the only contact affected by this. 
    anyone else experiencing this?  any help?  thanks!

    You’re vaguely talking about timestamps here, without specifying whether they are “sent” or “received”.
    The Date header is set by the sender’s mail client and corresponds to the Date Sent column, not to the Date Received column.
    The date that Mail shows in the Date Received column is the date that appears in the latest (topmost) Received header (which you can see doing View > Message > Long Headers), and is set by your incoming mail server.
    Obviously, the timestamp set by the sender’s mail client doesn’t have to be the same as the timestamp set by your incoming mail server when it received the message, amongst other reasons because both the sender’s computer and your incoming mail server may be configured incorrectly...

  • Mail Addresses and Address book Email Addresses

    hi all,
    i wasnt sure how to search this problem, so i thought just make a new post. do apolisge if this has already been answered somewhere.
    i wanted to know are the addresses in mail directly linked to addresses from Address book. because the two applications seem to be doing a few wierd things.
    1) when i type a name, it begins to come up. but then it comes up with a surname. and when i look in address book its there also. so i delete it but still find that the surname is still there.
    2) in mail - the surname gets filled in somehow. dont know where it gets the information.
    is there any way to reset the addresses that are saved in mail. and make sure it only gets the names in address book.
    note: i also sync the address book with my Nokia N70.
    any suggestions or help will be appericated.
    Thanks,
    Snoop
    PB G4 1.5ghz 15" 1.5gb ram & 20" iMac 2.16GHZ Intel Core 2 Duo 2gb RAM Mac OS X (10.4.8) 19" TFT, 250gb ext HDD, iPod 40gb 4thGen, iPod 30gb Video 5thGen

    Mail has a list of previous recipients that it supplements the Address Book information with. If something is showing up that isn't in the Address Book, go to Window -> Previous Recipients in Mail and you should find it in there. Remove anything you don't want to be there.

  • Why Address Book email addresses without first&last name stacked up under random names when moved to Lion?

    Often in Snow Leopard I would add an email address to my address book wihtout filling in the name fields. For example, Iif I got an email from [email protected], I would "add to address book but never fill out the card completely with the first and last names. The card showed with just an email address. Just left it as the email address. I never had any problems doing this and it always showed up as a single email address on a single card. Oh woe is me! When I moved to Lion I now have multiple unrelated email addresses under some of these "email only" cards. These seem to be the folks who were cards as an email address w/o first and last name fields. Not only that, I have multiples of the "email only cards" and each one has a different set of mutliple "email only" addresses under it. But, at least one of the "email only cards" just has the desired email w no other info. Can I fix this other than manually?
    I now have a disaster of an Address book.

    ok, I've spent some time doing various scenarios.
    I have managed to replicate one scenario which does as you say.
    If my contact in the address book:
    With name details as Peter Foo
    email address: [email protected]
    where there is an inserted space before the name peter, of course this is not instantly noticeable, but it is as if you hit the space bar just before typing the email address.
    Then when I use the Contacts Sidebar in a Write message, it will add the email address like this:
    Peter Foo <" peter"@somewhere.com>
    which of course in invalid.
    but in the address book, if highlight the contact, in the section below the email address in blue -if I click this to send an email the email address is printed exacly with the space and it will send as if nothing is wrong.
    So i'm asking you to check those email addresses which insert incorrectly via the Contacts sidebar. They only do this for me if there is a hidden inserted space at the start of the email address.

  • Address book duplicates, address book duplicates

    My Address book is duplicating contacts. It will not search. I cannot merge duplicates as it freezes/hangs on the merging sequence. What to do? I have Mac OS X Lion Version 10.7.2 with a 2.8 GHz Intel Core i5 Processor and 16 GB  1333 MHz DDR3, my Graphics ATI Rdeon HD 5750 1024 MB.

    You have duplicates because you are using two accounts that have the same information in them. You need to eliminate one of the accounts and then check again. If you still need help then navigate to the iCloud on my Mac forum and someone can provide more insight on how to fix the issue.

  • Recovering backup duplicates address book... how can I fix ?

    Hi everyone, i´m BES and NOTES administrator in my company in Brazil, some employers are reclaim me the adress book of blackberry 9000 ( and 8900 and 8300) are duplicating !
    this is the problem: when the employer receive the new BlackBerry, he make a backup of address book, and then recover this backup on the new phone, but ON the adress book dont appears DESKTOP, appears UNKNOWN... so, when the sync starts, duplicates all address becouse it creates a new book called DESKTOP.. how can I fix this?
    thankzz

    For those that don't want to download any additional software and Just want to make a return label you can also duplicate your own address card within the address book application the number of times you need it in on your label sheet. Highlight them all, then print. Once you've finished you can just type in your own name in the search bar and delete everything except your original card which is obvious because that card has the shadow of a person.
    The other way around this is to make a card called Return Address. and put your name and address in the address area. Duplicate the card so that you have the same about cards as labels, print and then delete when you have finished.
    I am not saying this way is perfect but at least there is a work around if you need it.
    Have a good day.

Maybe you are looking for