Apple Script to Delete specific date from Contacts

Imported some contacts from Outlook. Microsoft got revenge by exporting 11/30/1999 for birthdays and anniversaries that were blank. Every 11/30 my birthday calendar fills up completely. One at at time deletion is too slow. I'd like to do an Apple script that finds all contacts with 11/30/1999 as birthday or anniversary and deletes it.


Running MacOS 10.12.2 Beta on an Mid2014 15 inch Retina with 2.8 GHz Intel Core i7 and 16 gig ram.

MacBook Pro (Retina, 15-inch, Mid 2014), macOS Sierra (10.12.1), Actually, it's 10.12.2

Posted on Nov 27, 2016 11:37 AM

Reply
26 replies

Dec 6, 2016 8:53 AM in response to Barney-15E

As soon as I invoked the new script I go this error:

error "Contacts got an error: Can’t make birthdate of person id \"7CA9D357-C10D-4427-9986-6F40FAE3C3C3:ABPerson\" into type specifier." number -1700 from birthdate of person id "7CA9D357-C10D-4427-9986-6F40FAE3C3C3:ABPerson" to specifier



I see in the script that birth date was changed in color from blue to magenta?

Dec 6, 2016 8:56 AM in response to Barney-15E

I invoked the new script and got this error:

error "Contacts got an error: Can’t make birthdate of person id \"7CA9D357-C10D-4427-9986-6F40FAE3C3C3:ABPerson\" into type specifier." number -1700 from birthdate of person id "7CA9D357-C10D-4427-9986-6F40FAE3C3C3:ABPerson" to specifier


I note that the the line "set birthday to (birth date of thePerson)" changed the color of birth date from blue to magenta.

Dec 8, 2016 6:53 AM in response to Barney-15E

tell application "Contacts"

set thePeople to people

repeat with i from 1 to number of items in thePeople

set thePerson to (item i of thePeople)

set birthday to (birth date of thePerson)


if birthday is greater than or equal to date "Tuesday, November 30, 1999 at 12:00:00" and birthday is less than date "Wednesday, December 1, 1999 at 12:00:00" then

set the birth date of thePerson to missing value

end if

set theDates to (custom dates of thePerson)

if theDates is not {} then

repeat with j from (count of items in theDates) to 1 by -1

set dateValue to value of (item j of theDates)

set theLabel to label of (item j of theDates)

if dateValue is greater than or equal to date "Tuesday, November 30, 1999 at 12:00:00" and dateValue is less than date "Wednesday, December 1, 1999 at 12:00:00" and theLabel = "anniversary" then

set the value of (item j of theDates) to missing value

end if


end repeat

end if

end repeat

save

end tell


--ok, i popped a space into birthdate to make it birth date and ran it again. I got this error:

Result:

missing value

Did I misunderstand?

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Apple Script to Delete specific date from Contacts

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.