Here is an Address Book script plugin install in ~/Library -> Address Book Plug-Ins. Open a new document in Script Editor, copy the text below, and paste it into the document. Then save the script file in ~/Library -> Address Book Plug-Ins, and call this file anything you want)
(* This script adds a popup to birthday field that shows the persons age *)
using terms from application "Address Book"
on calculateAge(bdate)
set age to ((year of (current date)) - 1 - (year of bdate))
if (month of (current date) > (month of bdate)) then
set age to age + 1
else if (month of (current date) = (month of bdate)) then
if (day of (current date) ≥ (day of bdate)) then
set age to age + 1
end if
end if
return age
end calculateAge
on action property
return "birth date"
end action property
on action title for p with e
set userAge to calculateAge(e)
return (name of p & " is " & (userAge as string)) & " years old"
end action title
on should enable action for p with e
return true
end should enable action
on perform action for p with e
set userAge to calculateAge(e)
display dialog (name of p & " is " & (userAge as string)) ¬
& " years old"
end perform action
end using terms from
[
robg adds: This works as expected on my machine; to activate it, just control-click on the Birthday field (assuming you've filled in a value!). You will have to add Birthday to your template via the Preferences if you haven't done so already.]