Find recently-modified Address Book entries

Feb 20, '09 07:30:04AM

Contributed by: michaelbach

After I Moved all my contacts from Now Up-To-Date the the Address Book, I slowly learned to live with Address Book's limitations. For various reasons (e.g. after synchronizing), however, I would like to know which contacts have changed.

The following AppleScript does just that for you. The output is placed on the clipboard, and formatted to be pasted into a spreadsheet. But since you have the code, you can modify ad lib. Enjoy!

(* Find recently modified entries in the Address Book

Input: a time interval (backwards from today) in the variable "daysBeforeToday"
Output: a string on the clipboard, format: YYYY-MM-DD (tab) Name (return)

©2009, Michael Bach, <www.michaelbach.de> *)

set daysBeforeToday to 7 -- <<<  change as desired or read from a dialog

tell application "Address Book"
  copy (current date) - daysBeforeToday * 24 * minutes * 60 to referenceDate
  copy (every person whose (modification date > referenceDate)) to modifiedPersons
  set s to ""
  repeat with aPerson in modifiedPersons
    set d to ((modification date) of aPerson) -- now change to international format and forget the hours
    set dateString to (year of d as string) & "-" & (my twoDigits((month of d) as number)) & "-" & (my twoDigits(day of d) as string)
    set s to s & dateString & tab & (name of aPerson) & return
  end repeat
  set the clipboard to s --for pasting into other applications
  s -- to view immediately in the script editor
end tell

on twoDigits(aNumber) -- trivial utility for formatting
  if aNumber < 10 then return "0" & (aNumber as string)
  return (aNumber as string)
end twoDigits
[robg adds: This worked as described for me, in 10.5.6. I'm not sure about 10.4.x compatibility.]

Comments (13)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20090218052324712