Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Address Book plug-ins and 'custom date' fields' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Address Book plug-ins and 'custom date' fields
Authored by: amethyst on May 27, '05 05:45:39PM
This applescript is modified from a birthday calculator applescript I found on one of the applescript tutorials. It's a good starting place to work with custom dates.

using terms from application "Address Book"
	on calculateDate(cdate)
		set age to ((year of (current date)) - 1 - (year of cdate))
		if (month of (current date) > (month of cdate)) then
			set age to age + 1
		else if (month of (current date) = (month of cdate)) then
			if (day of (current date) >= (day of cdate)) then
				set age to age + 1
			end if
		end if
		return age
	end calculateDate
	
	on action property
		return "custom date"
	end action property
	
	on action title for aPerson with aDate
		set userDate to calculateDate(value of aDate)
		if userDate <= 0 then
			return "Date Unknown"
		else
			return label of aDate & ":  " & ((userDate as string)) & " years"
		end if
	end action title
	
	on should enable action for aPerson with aDate
		set userDate to calculateDate(value of aDate)
		if userDate <= 0 then
			return false
		else
			return true
		end if
	end should enable action
	
	on perform action for aPerson with aDate
		set userDate to calculateDate(value of aDate)
		if userDate <= 0 then
			display dialog ("Date Unkown")
		else
			display dialog (label of aDate & ":  " & (userDate as string)) ¬
				& " years"
		end if
	end perform action
end using terms from


[ Reply to This | # ]