Forums

Discuss all things Remember The Milk.

Birthday Reminders in RTM - AppleScript

(closed account) says:
I wanted to setup a way of getting automatic tasks sent to RTM when someone's birthday was coming up. I know I could just add repeating tasks for birthday reminders, but I wanted a bit more control over it, so it could be automated from my address book. i.e. if I added a contact to my mac address book then their birthday would automatically get sent to RTM as a reminder. 



So, I wrote a little AppleScript to do this. 



It will automatically send a task email to your RTM inbox a week in advance of someone's birthday, with details of the day & date of their birthday, the age they will be, and their postal address as a note in the task! Then I have all the info I need in RTM to send them a card!



Just paste the following code into your AppleScript editor, and run it to test. Make sure you enter the relevant fields below in the "theemail" section, i.e. after "From" enter your email address enclosed in left & right arrow symbols, and after "To" your RTM inbox email address. Then the "sendmail -bm " should also be to your RTM inbox email address.



You can also tweak the subject and body of the email message to be as you like, i.e. task name will be taken from the subject, and you can change the tags to whatever is relevant for you, where P: is priority, D: is due, O: is location and S: is tags.



I don't claim to be an expert at AppleScripting, in fact this is my first attempt, so there may be a better way of doing this. 



After setting the script up, I've added a weekly recurring event in iCal with the alarm type set to "Run Script", so the script gets run each week, automatically.

That's it! Now, every monday I get a task(s) automagically appear in my RTM inbox if someone's birthday is coming up in the next 7 days. Looks something like this:

======================================

It's Bob the Monkey's Birthday this Monday (4 years old on Monday, 12 October 2009), send a card

Due: Mon 12 Oct 09
Repeat: never
Time estimate: none
Tags: .birthdays, @errand
Location: Home
URL: none
Postponed: 0 times
Sent from: Emailed in
Notes: 1

======================================


And here's the code, just copy from below the line, and paste into AppleScript editor:


======================================


set m to month of (current date)
set d to day of (current date)
set w to weekday of (current date)
set y to year of (current date)
tell application "Address Book" to tell (people whose birth date is not missing value)
repeat with thisPerson in it
set thebirthday to thisPerson's birth date as date
set theyear to year of thebirthday
set year of thebirthday to (current date)'s year
set shortbirthday to date string of thebirthday
set ab_m to month of thebirthday
set ab_d to day of thebirthday
set ab_w to weekday of thebirthday
if ab_m = m and ab_d ≥ d and ab_d < d + 7 then
set theage to (y - theyear)
set thestreet to street of (addresses of thisPerson)
set thetown to city of (addresses of thisPerson)
set thecounty to state of (addresses of thisPerson)
set thezip to zip of (addresses of thisPerson)
set thecountry to country of (addresses of thisPerson)
set thename to thisPerson's name
set thefirstname to thisPerson's first name
set birthdayfile to ".birthdayemail.txt"
set theemail to "Subject: It's " & thename & "'s Birthday this " & ab_w & " (" & theage & " years old on " & shortbirthday & "), send a card
From: Your Name
To: Remember The Milk

P:1
D:today
O:Home
S:.birthdays,@errand
---
Address:

" & thestreet & "
" & thetown & "
" & thecounty & "
" & thezip & "
" & thecountry & "
---

"
set filelocation to my createemail(birthdayfile, theemail)
do shell script "sendmail -bm yourRtmInboxEmailAddress < " & filelocation
do shell script "rm " & filelocation
end if
end repeat
end tell

on createemail(the_filename, the_list)
set docFolder to (path to desktop as string)
set docName to docFolder & the_filename as list
set docunix to POSIX path of docFolder & the_filename
set docPointer to (open for access docName with write permission)
set eof of docPointer to 0
write the_list to docPointer as string
close access docPointer
return docunix
end createemail
Posted at 4:40pm on May 13, 2009
emily (Remember The Milk) says:
Hey odelaney,

This is a really creative tip -- thanks for sharing this!

Your tip is this week's Tips & Tricks Tuesday winner. We've added a free year of Pro to your RTM account. :)
Posted 14 years ago
(closed account) says:
This is a great tip!

This gave me an idea to try and do this in Facebook, but I can't seem to use my RTM e-mail for it. Oh well.
Posted 14 years ago
jennie says:
Ooh, this is a good one! Thanks, odelaney!
Posted 14 years ago
james.bao says:
I tried out this tip but there seems to be a bug. If there are two birthdays right next to each other, the script will send one birthday TWICE, instead of two different birthdays...
Posted 14 years ago
(closed account) says:
Hmmm. Strange. "next to each other" as in two different people's birthdays on the same day? I'll check it out and see if I can fix it.
Posted 14 years ago
(closed account) says:
@james.bao, OK. I created two new contacts with today as their birthday, ran the script and it worked fine, with two separate tasks created in RTM.

Can you run the script manually and send me the output and I'll see if I can figure out what's wrong.

Double click the .scpt file you created to open it in Script Editor, then click the "Event Log" button at the bottom of the window, click "Run" to run the script, and email me the output to odelay@me.com.
Posted 14 years ago
glen.brackett says:
Hi, your script is just what I was looking for and want to use it. I am having difficulty though, when I run the script and watched the "Event Log", it shows the email created, the problem is it doesn't seem to be actually sending it.

Any ideas? thanks Glen
Posted 14 years ago
(closed account) says:
Have you changed the relavant fields to your email address, and your RTM inbox email address?

These forums are a real pain, and won't let me use the arrow brackets to show exactly how it should display, so here's what it should look like in an image (I've used bogus email addresses here, but the fields in red are the ones you need to change to your specific email addresses). Just make sure you use the arrow brackets for the first two lines - i.e. the "To" and "From" fields

Posted 14 years ago
andrew.wilkie says:
This is great, exactly what I'm looking for, but what if you're not using Apple?
Posted 13 years ago
Log in to post a reply.