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

An Address Book plug-in to show age in years Apps
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.]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[4,962 views]  

An Address Book plug-in to show age in years | 6 comments | Create New Account
Click here to return to the 'An Address Book plug-in to show age in years' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An Address Book plug-in to show age in years
Authored by: simX on Feb 11, '04 05:30:27PM

I wish that people, when writing AppleScripts, wouldn't use confusing variables like "p" or "e". Use a much more descriptive variable, so people know what you're talking about!



[ Reply to This | # ]
An Address Book plug-in to show age in years
Authored by: robg on Feb 11, '04 05:39:22PM

In another hint (which I can't find right now), this was discussed - it's not the script author doing the bad naming; I believe it's Apple's AppleScript library for AddressBook ...

-rob.



[ Reply to This | # ]
An Address Book plug-in to show age in years
Authored by: dmmorse on Feb 12, '04 12:40:43AM
This hint is a repeat of this hint I posted a few weeks ago.

[ Reply to This | # ]
An Address Book plug-in to show age in years
Authored by: skybolt on Feb 12, '04 11:11:08AM

I'm very new to scripts, so expect I've done something wrong, but when I followed the instructions, I got an error message that it could not be saved (not at the mac right now, so can't remember exactly - something like "." not recognized, as I recall). Was I supposed to "compile" or something? Thanks in advance, sure would love to learn to use these scripts, and maybe someday learn to write my own!

---
Mary



[ Reply to This | # ]
An Address Book plug-in to show age in years
Authored by: Number Three on Feb 20, '04 03:09:58PM

Once you copy and paste it, remove all of the \'s before "'s. This is an error in MacOSXHints.com's PHP coding. You can hit compile to see if there are any errors in the code before trying to save it.

---
Everyone knows Custard died at Little Bighorn. This novel suggests... maybe he didn't?



[ Reply to This | # ]
An Address Book plug-in to show age in years
Authored by: P.R.Deltoid on Feb 21, '04 04:45:51PM

There appears to be a problem with this (and apparently all) Address Book Plug-ins in Address Book 3.1.1 (v301) in Panther 10.3.2: the script will work only once, and will not work again until Address Book is relaunched. Dialog boxes also will not display, even when their message strings are defined as litterals.

Hopefully this is just a bug that will be fixed in the 10.3.3 update.


---
To PC Users: "What gets into you all...? Is it some devil that crawls inside [your machine]?" -P.R. Deltoid

[ Reply to This | # ]