MacOS – Cleaning up birth years 2000 in the Address Book

applescriptcontactsmacos

A few years ago (or actually, more likely, in 2000), for some reason, birthdays that didn't have a birth year (but did and do have correct month and day) were automatically given the birth year 2000 in my Address Book. There are hundreds of them (among thousands which are fine).

Is there a way to select these cards, perhaps by Smart Group or something similar, so that I may manually remove the birth year 2000?


NB: I just might also be able to run an AppleScript with a little help. 🙂 OS X 10.8.5 installed.

Best Answer

Try:

set targetYear to "2000"
set targetGroup to {}

tell application "Address Book"
    set thePeople to every person whose birth date ≠ missing value
    repeat with aPerson in thePeople
        set birthYear to (aPerson's birth date)
        if my yearCheck(birthYear, targetYear) then set end of targetGroup to (contents of aPerson)
    end repeat
    if targetGroup ≠ {} then set selection to targetGroup
    activate
end tell

on yearCheck(theDate, theYear)
    if theYear = (year of theDate as text) then return true
    return false
end yearCheck

Added by the OP for novices like him. This works. What I did: Open Address Book, click All Contacts, close Address Book, close the Internet connection (just to be sure), copy-paste the above script into AppleScript Editor, press Compile, press Run, wait until "Running..." disappears. Address Book is now open with the cards with 2000 selected. Put those in a Group for further work...