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

Create Growl alerts for Address Book contacts' birthdays Apps
I have a lot of people in my Mac OS X Address Book. I thought it would be a nice idea to have the system check the birthdays in Address Book, and inform me of any forthcoming birthdays via a Growl notification. So I've created an Apple Script to do that (with a lot of help from a few other peoples).

First, install Growl if it isn't installed. Also install the Terminal growlnotify command, which you'll find in the Extras folder on the Growl disk image. Next, copy and paste the following into AppleScript Editor:
delay 0.5
set isRunning to 0
set timer to the time of the (current date)

repeat while isRunning = 0
  tell application "System Events"
    set isRunning to 
      ((application processes whose (name is equal to "GrowlHelperApp")) count)
        
  end tell
  
  if isRunning ≥ 1 then
    --try 
    MyScript()
    --   end try 
  else if (the (time of the (current date)) - timer) > 2 then
    set isRunning to -1
    quit
  end if
  delay 1
end repeat

on MyScript()
  set birthdayPeople to {}
  set birthdayDates to {}
  set birthdayMonths to {}
  set birthdayAge to {}
  set birthdayPeopleToday to {}
  set birthdayDatesToday to {}
  set birthdayMonthsToday to {}
  set birthdayAgeToday to {}
  set message to ""
  set messageToday to ""
  set endOfYear to false
  -- Get the current date & next week 
  
  set today to current date
  set todayDate to day of today
  
  set nextWeek to today + (60 * 60 * 24 * 7)
  if (hours of today) is greater than 11 then
    set today to today - (60 * 60 * 24)
  end if
  if (year of nextWeek) is greater than (year of today) then
    set endOfYear to true
  end if
  -- Loop through everyone in the Address Book 
  tell application "Address Book"
    set peopleArray to the name of every person
    repeat with i from 1 to count of peopleArray
      set thisPerson to person i
      set thisBirthday to birth date of thisPerson
      
      -- Check if they've got a birthday entered on their card 
      if thisBirthday is not equal to (missing value) then
        set whichMonth to (month of thisBirthday) as number
        if ((endOfYear is true) and (whichMonth = 1)) then
          set peopleAge to ((year of today as number) - (year of thisBirthday as number) + 1) as string
          set year of thisBirthday to (year of today) + 1
        else
          set peopleAge to ((year of today as number) - (year of thisBirthday as number)) as string
          set year of thisBirthday to year of today -- otherwise it uses their birth year 
        end if
        -- See if it's in the next week 
        if (thisBirthday is greater than today) and (thisBirthday is less than nextWeek) then
          set thisBirthday_day to day of thisBirthday
          set thisBirthday_month to month of thisBirthday as number
          -- Add them to our list 
          if (todayDate) is equal to thisBirthday_day then
            set birthdayPeopleToday to birthdayPeopleToday & name of thisPerson
            set birthdayDatesToday to birthdayDatesToday & thisBirthday_day
            set birthdayMonthsToday to birthdayMonthsToday & thisBirthday_month
            set birthdayAgeToday to birthdayAgeToday & peopleAge
          else
            set birthdayPeople to birthdayPeople & name of thisPerson
            set birthdayDates to birthdayDates & thisBirthday_day
            set birthdayMonths to birthdayMonths & thisBirthday_month
            set birthdayAge to birthdayAge & peopleAge
          end if
        end if
      end if
      
    end repeat
  end tell
  if ((count of birthdayPeople) is greater than 0) then
    repeat with i from 1 to count of birthdayPeople
      set message to message & item i of birthdayPeople & " (" & item i of birthdayAge & ") am " & item i of birthdayDates & "." & item i of birthdayMonths & "." & year of today & return
    end repeat
    --display dialog message 
    --modify the next line to reflect the location of your image, or remove the 
    --image reference. Also change the text as you wish.
    do shell script "usr/local/bin/growlnotify --image /Users/Nomis101/Applications/cake.gif -t 'Birthdays this week:' -m '" & message & "'"
  end if
  if ((count of birthdayPeopleToday) is greater than 0) then
    repeat with i from 1 to count of birthdayPeopleToday
      set messageToday to messageToday & item i of birthdayPeopleToday & " (" & item i of birthdayAgeToday & ")" & return
    end repeat
    do shell script "usr/local/bin/growlnotify -a 'Problem Reporter' -t 'Birthdays TODAY:' -m '" & messageToday & "'"
    --display dialog messageToday 
  end if
  tell application "Address Book"
    quit
  end tell
  quit
end MyScript
In the code, change the line that begins do shell script "usr/local/bin/growlnotify... so that it will work on your system. Notice there's a reference to an image that will appear in the Growl alert; either remove that whole bit, or change the path to point to your local image. Then adjust the text in the alert as you wish. (You'll also need to modify the path if growlnotify isn't in /usr/local/bin/.)

Save the code as an Application, and store it wherever you like. Open System Preferences » Accounts, and add your saved application as a Login Item.

One problem I had with the application as a login item is that it was too fast: Growl notifications don't work if Growl isn't loaded. So there is a detection for GrowlHelperApp included at the top of this script. This will cause the script to pause until Growl is fully loaded on login, and then execute the rest of the script.

This script worked just fine under Mac OS X 10.5. However, in 10.6 I have a problem where every time you execute this script, you will see Address Book for a short moment. So far, I haven't found a way to make this a background process. Apart from that, it also works just fine under 10.6.

[robg adds: I haven't tested this one.]
    •    
  • Currently 2.17 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (12 votes cast)
 
[7,303 views]  

Create Growl alerts for Address Book contacts' birthdays | 3 comments | Create New Account
Click here to return to the 'Create Growl alerts for Address Book contacts' birthdays' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create Growl alerts for Address Book contacts' birthdays
Authored by: mmnw on Mar 11, '10 07:43:40AM
You could use Growl's AppleScript Additions instead of growlnotify. The necessary documentation should have been installed with your Growl installation. This would also address your problems with GrowlHelperApp not being loaded, as AppleScript would wait for GrowlHelperApp to be loaded as soon as it finds a tell application "GrowlHelperApp".
Also installing it as a login item isn't a good idea in every case. Many people never logout their account. For example on my MacBook Pro I never ever log out or shut down (except for updates). I just close the lid and send it sleeping.
A better solution would probably be to install the Script as a repeating LaunchAgent via launchctl or Lingon.

[ Reply to This | # ]
Create Growl alerts for Address Book contacts' birthdays
Authored by: kentmartin on Mar 11, '10 08:09:10AM

Nice work, but for a much simpler (and waaaaay more comprehensive) solution, I'd suggest omnigrowl http://www.woodenbrain.com/products/omnigrowl/omnigrowl.html

It is shareware, but fully functional as a trial.



[ Reply to This | # ]
Create Growl alerts for Address Book contacts' birthdays
Authored by: strunx on Mar 12, '10 07:04:28AM

Is there any way to show the persons image from adressbook instead of the ..reference to an image that will appear in the Growl alert...?



[ Reply to This | # ]