User Tools

Site Tools


code:applescript:age

This is an old revision of the document!


Calculate the age of a person in Apple's Adress Book

using terms from application "Address Book"
	on age(e)
		set cy to (year of (current date))
		set y to (cy - (year of e))
 
		set cd to (day of (current date))
		set cm to ((month of (current date)) as integer)
 
		set d to (day of e)
		set m to ((month of e) as integer)
 
		if (cm ≤ m) and (cd < d) then
			return y - 1
		else
			return y
		end if
	end age
 
	on action property
		return "birth date"
	end action property
 
	on action title for p with e
		-- return (age(e) as string) & " years old"
		return (age(e))
	end action title
 
	on should enable action for p with e
		return true
	end should enable action
 
	on perform action for p with e
		display dialog (name of p & " is " & (age(e)) as string) & " years old"
		return true
	end perform action
end using terms from
code/applescript/age.1131114546.txt.gz · Last modified: 2005/11/04 14:29 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki