#!/bin/bash
# Lists contacts added in the past 24 hours
# bash shared/projects/notes/resources/recent_contacts.sh

osascript <<'EOF'
tell application "Contacts"
	set cutoff to (current date) - (1 * days)
	set output to ""

	repeat with aPerson in every person
		set createdOn to creation date of aPerson
		if createdOn > cutoff then
			set fn to first name of aPerson
			set ln to last name of aPerson
			if fn is missing value then set fn to ""
			if ln is missing value then set ln to ""
			set output to output & fn & " " & ln & " (added: " & createdOn & ")" & linefeed
		end if
	end repeat

	if output is "" then
		return "No contacts added in the past 24 hours."
	end if
	return output
end tell
EOF
