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

Address Book plug-ins and 'custom date' fields Apps
I've learned quite a bit about writing Address Book plugins in Applescript here at MacOSXHints, and thought I'd add a bit that I've learned. Although "custom date" isn't listed in the Address Book Applescript Dictionary and I haven't seen any example scripts using it, it does work so you can write plugins that use any custom date fields you've created.

Also important to know is that the custom date object is the only one that doesn't return the value of the object as a default -- you have to specifically use (value of <object>) to get the date in the field. And by using (label of <object>) you can write scripts that do different things for differently labeled fields. For example, I have one that will show the upcoming numbered Anniversary for one labeled 'Anniversary,' but for any other, will just show how many years and days since that date have passed.

Hope that helps anyone who might be writing their own plugins.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[8,972 views]  

Address Book plug-ins and 'custom date' fields | 5 comments | Create New Account
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: Greedo on May 10, '04 12:33:04PM

You say "for example..." and then don't provide an example.

Come on, share! :)



[ Reply to This | # ]
Address Book plug-ins and 'custom date' fields
Authored by: dmmorse on May 11, '04 12:40:22AM

I agree with Greedo, please share!!

You should know that I am biased because I am one of the readers here who previously posted a hint on Address Book plug-ins.



[ Reply to This | # ]
Address Book plug-ins and 'custom date' fields
Authored by: BobVB on May 11, '04 07:00:58PM
Sorry, its just my code that figures out the days left is a nightmare and I think it doesn't even do it accurately in some cases. Here is a bit of code that illustrates what I'm talking about with 'custom date'

using terms from application "Address Book"
	on action property
		return "custom date"
	end action property
	
	on action title for p with e
		set theAge to my ageForDate(value of e)
		if label of e is equal to "Anniversary" then
			return "next is " & (theAge + 1 as string) & fancy(theAge + 1) & " anniversary"
		else
			-- set theAge to theAge as string
			return (theAge as string) & " years since then"
		end if
	end action title
	
	on should enable action for p with e
		return false
	end should enable action
	
	on perform action for p with e
		return true
	end perform action
	
end using terms from

on ageForDate(e)
	set d to current date
	set age to (year of d) - (year of e)
	if month of d < month of e then set age to age - 1
	if (month of d = month of e) and (day of d < day of e) then set age to age - 1
	return age
end ageForDate

on fancy(num)
	set idstr to "stndrdth"
	set wnum to (num mod 100)
	if (wnum > 10) and (wnum < 14) then
		set myend to "th"
	else
		set wnum to ((((num mod 10) - 1) * 2) + 1)
		if wnum > 5 then
			set myend to "th"
		else
			set myend to characters wnum thru (wnum + 1) of idstr as string
		end if
	end if
	return myend
end fancy


[ Reply to This | # ]
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 | # ]
Address Book plug-ins and 'custom date' fields
Authored by: ableyer on Mar 15, '07 01:09:09PM

I imported 260 contacts using other date and other name for 2 of the fields... How would I go in and batch change the "other" to a customized label?



[ Reply to This | # ]