Manipulating Address Book Birthdays

Hi,

I’ve made a script that reminds me of upcoming birthdays, but my birthday scanning function runs slowly (it’s a repeat). Can anyone think of a way to optimize this code?


tell application "Address Book"
	repeat with theperson in (every person whose birth date is not missing value)
		set birthdate to birth date of theperson
		if (month of birthdate is month of (current date) and day of birthdate is day of (current date)) then my birthdaynotify(the name of theperson, round (((current date) - birthdate) / days / 365.2423) rounding down, image of theperson)
	end repeat
end tell

I’ve tried selecting people whose birthdays are today (well this month for simplification) directly with the following “whose” statement without success.


tell application "Address Book" to return people whose month of birth date is month of (current date)

Thanks in advance,

Ben

Ben:

I don’t have any birthdates in my Address Book entries, so I cannot test this, but try setting the month and day to variables and see if that speeds it up; that way it should reduce the number of iterations needed per loop.

set {this_day, this_month} to {day of (current date), month of (current date)}
tell application "Address Book"
	repeat with theperson in (every person whose birth date is not missing value)
		set birthdate to birth date of theperson
		if (month of birthdate is this_month and day of birthdate is this_day) then my birthdaynotify(the name of theperson, round (((current date) - birthdate) / days / 365.2423) rounding down, image of theperson)
	end repeat
end tell