Skip to content

Instantly share code, notes, and snippets.

@brettkelly
Created November 11, 2011 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brettkelly/1359667 to your computer and use it in GitHub Desktop.
Save brettkelly/1359667 to your computer and use it in GitHub Desktop.
Delete Selected Birthdays from Address Book
(*
Brett Kelly wrote this.
http://nerdgap.com
*)
tell application "Address Book"
-- init our lists of stuff
set peeps to every person
set bdays to {}
set bdaynames to {}
set deleteBday to {}
-- collect all of the Address Book entries that have a birth date set
repeat with peep in peeps
if (birth date of peep) is not missing value then
set pname to name of peep as text
set pid to id of peep
set pbday to birth date of peep as text
set myRec to {name:pname, birthday:pbday, id:pid}
set the end of bdays to myRec
copy name of peep as text to the end of bdaynames
end if
end repeat
-- if there are more than 0 birthdays, ask the user which ones to delete
if (count bdays) > 0 then
set deleteBday to ¬
choose from list bdaynames ¬
with title "Victim Chooser" with prompt "Remove Birthdays For:" with multiple selections allowed
else
display dialog "No birthdays found. Oof!" buttons {"OK"} ¬
with icon stop
return
end if
-- if they selected at least one entry, do the deed (with confirmation, naturally)
if deleteBday is not equal to false then
set cmsg to "You're about to delete " & (count bdays) & " birthday(s). Continue?"
set qproceed to (display dialog cmsg buttons {"Yes", "No"} with icon caution)
set qbutton to the button returned of the result
if qbutton as text is equal to "Yes" then
repeat with dBday in deleteBday
repeat with bday in bdays
if (name of bday as text) contains dBday then
set p to item 1 of (every person whose id is (id of bday))
delete birth date of p
save p
end if
end repeat
end repeat
end if
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment