You’re the kind of person who forgets a lot of crap, and you’re looking for something to set Todo items in your iCal for you, while you’re somewhere without actual access to your iCal.
Look no more.
Apple Mail allows you to set Rules on incoming mail. It has the standard action stuff of course — move to folder, mark as junk, trash-because-I-don’t-like-this-person, etc. But also one action that allows for some really interesting stuff: Run Applescript.
So I figured I could use that for some simple remote Todo-ing, via e-mail. I can send those from my phone if need be.
Now, there are a few scripts out there that will do similar things. I found, however, that they’re all closed. No sources. For an applescript. They could be doing <i>anything</i> to your system, and you wouldn’t know it. You might find your entire home directory empty after sending three todos. So here’s an open one instead. It’s fairly small so I’ll just paste it:
tell application "Mail"
-- What must the subject start with? This gets trimmed.
set thePrefix to "TODO: "
-- What calendar will we add the todo to?
set theCalendar to "Home"
set theMessages to (messages of inbox whose read status is false)
repeat with mail in theMessages
if the subject of the mail begins with thePrefix then
set theSummary to trim_line(the subject of the mail, thePrefix) of me
set theDescription to the content of the mail
tell application "iCal"
make new todo at the end of todos of (every calendar whose title = theCalendar) with properties {summary:theSummary, description:theDescription}
end tell
-- can't delete unread messages?
set read status of the mail to true
delete the mail
end if
end repeat
end tell
-- taken from apple.com and modified
on trim_line(this_text, trim_chars)
set x to the length of the trim_chars
repeat while this_text begins with the trim_chars
try
set this_text to characters (x + 1) thru -1 of this_text as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
return this_text
end trim_line
Don’t you love how Applescript looks? Anyway, paste in Script Editor, compile, notice it looks even better with colour and indenting, save the resulting script somewhere sane, and make a new Rule in Mail to process e-mails. The minimum I would recommend is a subject check on it beginning with ‘TODO: ‘. Add other checks as you see fit. Last, set the action to ‘Run Applescript’ and point to the script (really? yes.)
Try it out and have fun.
Hi There!
It looked exactly what i was searching for but unfortunately it don’t work, Wat a pitty!
Now i am not famliar with applescript but think i know how to implement this, but as i said, it doesn’t work!
I copied it into the script editor and tried to chance the names of the ical ie. ‘Astrid’ instead of ‘Home’ and also tried to change the name of TODO but nothing happens really. Of course I activate it in the mail rules.
Any solution?
Reinier
Well, I just tried it myself a second time, after copying the script from here myself and it all worked fine even after changing the values.
The ‘TODO: ‘ (thePrefix) in the script and the name of the calendar (theCalendar) need to match precisely to the name in iCal and the subject you send your e-mails with. As far as I know, there is no way for Mail to tell you what e-mail(s) it’s running the script for, so it checks the inbox for unread messages with a matching subject.
Are you sure Mail is running the script when a todo mail arrives? You could add another Action (like setting a colour or flagging it) to make sure. Also, the e-mail needs to be unread or the script won’t know it’s new. As far as I know, there isn’t any other way to do that.
Good luck.
Thanks for your comment but…unfortunately it won’t work here.
I did it like this very simple
tell application “Mail”
– What must the subject start with? This gets trimmed.
set thePrefix to “TODO: ”
– What calendar will we add the todo to?
set theCalendar to “TEST”
set theMessages to (messages of inbox whose read status is false)
repeat with mail in theMessages
if the subject of the mail begins with thePrefix then
set theSummary to trim_line(the subject of the mail, thePrefix) of me
set theDescription to the content of the mail
tell application “iCal”
make new todo at the end of todos of (every calendar whose title = theCalendar) with properties {summary:theSummary, description:theDescription}
end tell
To let this script work i have made a new calendar called TEST in iCal
and in Mail I attached the rule TODO to the script and gave it a colour.
I send myself a mail with the subject TODO:
The script is doing parcially the work it generates a blue marked mail but there it stops.
fyi I work with an iMac G5 new model OSX version 10.4.3, iCal version 2.0.3 and Mail version 2.0.5
Can you help me out here? I like to have this running!!
Thanks in advance, Reinier
[…] Marco at CyBeRHQ.nl has written an AppleScript that will add To Dos to iCal via a Mail.app message. […]
I tried to modify this script to only check mail box “TODO” with the following modified line:
set theMessages to (messages of “TODO” whose read status is false and the subject begins with thePrefix)
This way, I can have many unread emails in my inbox without suffocating the system. To get this to work I had to modify my rule to put “TODO” messages in the TODO Box.
THE PROBLEM:
When I ran the script, I got an error
Can’t get every message of “TODO”.
Any suggestions?
Thanks
Yes.
Try something like:
set theMessages to (messages of mailbox “TODO” of account “your e-mail account’s name as in preferences goes here” whose read status is false and subject begins with thePrefix)
Sweet, this is a great script! One question: How would I edit this so that I can send to-dos to different calendars, that I choose. That is, what would we have to change in this script if I wanted to send a to-do to my “home” calendar, and an different to-do to my “work” calendar”?
Thanks!
The easiest way would be to duplicate the script and edit each separately. Doing it in a single script would require substantial changes, because (and I don’t know why, really, because it seems like The Right Thing to do) I didn’t think of multiple todo calendars when I wrote it.
[…] You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site. Share and Enjoy:These icons link to social bookmarking sites where readers canshare and discover new web pages. […]
Doesn’t seem to work here, though the Mail rule is definitely being triggered.
[…] Mail Yourself iCal ToDos is an AppleScript that will add To Dos to iCal via a Mail.app message. Simply compile and save the script on his site. Attach it to an Apple Mail rule set to match. Email yourself the task to be added, and Mail.app will run the script, using the subject of the message as the title of the To Do and dumping the body of the email into the Notes. […]
The Script doesn’t work if executed by a rule. Reason: at the time the script is executed, the message isn’t in the inbox. Here is a script working from the “rules”:
using terms from application “Mail”
on perform mail action with messages theMessages for rule theRule
tell application “Mail”
– What must the subject start with? This gets trimmed.
set thePrefix to “TODO: ”
– What calendar will we add the todo to?
set theCalendar to “Private”
–set theMessages to (messages of inbox whose read status is false)
repeat with mail in theMessages
if the subject of the mail begins with thePrefix then
set theSummary to trim_line(the subject of the mail, thePrefix) of me
set theDescription to the content of the mail
tell application “iCal”
make new todo at the end of todos of (every calendar whose title = theCalendar) with properties {summary:theSummary, description:theDescription}
end tell
– can’t delete unread messages?
set read status of the mail to true
delete the mail
end if
end repeat
end tell
end perform mail action with messages
end using terms from
– taken from apple.com and modified
on trim_line(this_text, trim_chars)
set x to the length of the trim_chars
repeat while this_text begins with the trim_chars
try
set this_text to characters (x + 1) thru -1 of this_text as string
on error
– the text contains nothing but the trim characters
return “”
end try
end repeat
return this_text
end trim_line
additional correction:
using terms from application “Mail”
on perform mail action with messages theMessages for rule theRule
tell application “Mail”
– What must the subject start with? This gets trimmed.
set thePrefix to “TODO: ”
– What calendar will we add the todo to?
set theCalendar to “Private”
–set theMessages to (messages of inbox whose read status is false)
repeat with mail in theMessages
if the subject of the mail begins with thePrefix then
set theSummary to trim_line(the subject of the mail, thePrefix) of me
set theDescription to the content of the mail
tell application “iCal”
make new todo at the end of todos of (every calendar whose title = theCalendar) with properties {summary:theSummary, description:theDescription}
end tell
set theSummary to “”
set theDescription to “”
– can’t delete unread messages?
set read status of the mail to true
–delete the mail
end if
end repeat
end tell
end perform mail action with messages
end using terms from
– taken from apple.com and modified
on trim_line(this_text, trim_chars)
set x to the length of the trim_chars
repeat while this_text begins with the trim_chars
try
set this_text to characters (x + 1) thru -1 of this_text as string
on error
– the text contains nothing but the trim characters
return “”
end try
end repeat
return this_text
end trim_line
CTG’s worked great for me thanks!
- when using from a rule one cool thing you can do is filter the incoming TODOs to trash or another folder for reference
- customizing for different calenders is pretty easy … just make a duplicate of the script and alter the subject and the calender values in the script. Then create a new filter based on that new subject. For example I did subject ‘WORKDO’ for my ‘Work’ calendar and ‘MYDO’ for my ‘Home’
[…] comes in handy for that. I’m not that save in AppleScript, so with some inspiration from here and here I hacked together a little script, which gets the trick […]
So anybody got it to work?
For whatever reason the AppleScript command to add the todo to iCal isn’t correct in 10.5.3. This modification worked for me….
tell application “Mail”
– What must the subject start with? This gets trimmed.
set thePrefix to “TODO: ”
– What calendar will we add the todo to?
set theCalendar to “General”
set theMessages to (messages of inbox whose read status is false)
repeat with mail in theMessages
if the subject of the mail begins with thePrefix then
set theSummary to trim_line(the subject of the mail, thePrefix) of me
set theDescription to the content of the mail
tell application “iCal”
tell calendar theCalendar
make new todo at end with properties {summary:theSummary}
end tell
end tell
– can’t delete unread messages?
set read status of the mail to true
delete the mail
end if
end repeat
end tell
– taken from apple.com and modified
on trim_line(this_text, trim_chars)
set x to the length of the trim_chars
repeat while this_text begins with the trim_chars
try
set this_text to characters (x + 1) thru -1 of this_text as string
on error
– the text contains nothing but the trim characters
return “”
end try
end repeat
return this_text
end trim_line
This change got the script working for me in Leopard.
And if you want the body of the message added to the Todo item, you need to change this:
make new todo at end with properties {summary:theSummary}
to this:
make new todo at end with properties {summary:theSummary, note:theDescription}
Opps. I meant change to this:
make new todo at end with properties {summary:theSummary, description:theDescription}
This is brilliant, and might really help me out, but I need to modify it a bit, and I’m not sophisticated enough at programming to do it myself. Anybody out there who could help me?
What I want to do is dictate a note into my iPhone with the appropriate data. The email would read something like this:
–
Date: February 14th, 2009
Time: 6 o’clock PM
Subject: Dinner with Sarah
Alarm: 1 day before
–
I want to use the program Jott on my iPhone to dictate these sorts of emails while I’m in the car, so the message will contain a bunch of other header text that Jott will automatically insert. Ideally, I would like the script to simply find the lines beginning with “Date” or “Time,” strip that data out and add it to iCal with those parameters. Is something like that possible, or would it be ridiculously complicated?
I inevitably think of a million things I have to do while I’m driving, and I’m certainly not going to type them into my iPhone while I’m behind the wheel. If I could dictate them and have them just “magically” appear on my calendar/To Do list, that would be unbelievably useful. I would totally pay for a script that would do that.
Oh, one potentially useful thing: I operate my own domain, so I can have any email address I want. I could have “ToDo@mydomain” or “calendar@mydomain,” for example, so that the Mail Rule would apply to anything going to that address.
Anybody think they might be able to help?
Thanks,
– David
student nursing florida loan forgiveness nursing student loan forgiveness florida
plan health formulary upmc myhealth plan health upmc
care mi saginaw health covenant health saginaw covenant michigan care
What should I add to the script if I want to remove the signature of my email?
I am adding the content of the Message as description and summary of the new Todo but I want to remove the signature “Sent from my iPhone”.
This is wat I tried so far:
using terms from application “Mail”
on perform mail action with messages theMessages for rule TodoRule
tell application “Mail”
set thePrefix to “TODO”
set theSignature to “Sent from my iPhone”
set replaceEmpty to “1″
set theCalendar to “M Home”
set theMessages to (messages of inbox whose read status is false)
repeat with Mail in theMessages
if the subject of the Mail begins with thePrefix then
set theSummary to trim_line(the subject of the Mail, thePrefix) of me
set theDescription to replaceText(TheSignature, replaceEmpty, the content of the Mail) of me
tell application “iCal”
tell calendar theCalendar
make new todo at end with properties {summary:theDescription, description:theSummary}
end tell
end tell
set read status of the Mail to true
delete the Mail
end if
end repeat
end tell
end perform mail action with messages
end using terms from
on trim_line(this_text, trim_chars)
set x to the length of the trim_chars
repeat while this_text begins with the trim_chars
try
set this_text to characters (x + 1) thru -1 of this_text as string
on error
return “”
end try
end repeat
return this_text
end trim_line
on replaceText(find, replace, someText)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set someText to text items of someText
set text item delimiters of AppleScript to replace
set someText to “” & someText
set text item delimiters of AppleScript to prevTIDs
return someText
end replaceText
Probably it’s easier (and a good idea in general) to remove the signature from your iPhone. Go to Settings -> Mail -> Signature.
Michael iii, who was placed to have been gone to economic results by her government bardas.
Hello!
Check out
a marvelous search engine –
baza sie pojebala
P.S. Yahoo – everything will be found! Google: nothing was really lost…
Bye to everyone!
Hello!
Check out
a marvelous search engine –
baza sie pojebala
P.S. Yahoo – everything will be found! Google: nothing was really lost…
See you!
Hi everyone
I’ve recently found
an excellent search engine –
baza sie pojebala
P.S. Yahoo – everything will be found! Google: nothing was really lost…
See you!