 | odelaney 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 |