Blog

Creating Daylite Tasks From Mail App Script

On August 15, 2009, in Systems Engineering, by Adrienne Szewczyk
8

We use Daylite for keeping most of our contacts and opportunities organized.  One of the few frustrations with it has been the inability to quickly pull Mail messages into Daylite as tasks so they could be acted on later as appropriate and not clog up the inbox.  In keeping with a Getting Things Done (GTD) mentality for task management I needed a solution.

After some net digging (thanks to John Gruber for his post on Mail messages ID URLs and ‘Casper’ for a basic way to push data into Daylite) I was able to find a couple pieces to start the process and pulled together the script below.  It will take any selected messages in Mac Mail and add them to Daylite as tasks.  The email subject line becomes the task name and the body of the task includes a message link that can be used to bring up the original email again (just right click or control click that link in the Daylite task and select open URL) and up to 1000 characters of the message body.

Example of ctrl-clicking on the message URL.

To install the script, download the file and put it into:

~/Library/Scripts/Applications/Mail

You may need to create that directory (it didn’t exist yet for me).

Then make sure your scripts menu is turned by.  Activate it using the Applescript utility (in Applications/Applescript/Applescript utility) and then check the ‘show script menu in menu bar’.

Now you can select the script ‘Add Daylite Tasks’ and it will add the new tasks to the Daylite Inbox.

This script has very little error handling so use at your own risk for now (and let me know if you find issues).

The final ease of use factor comes from using MailActOn which lets you set up a key combo to run a rule.  I’ve used this previously for quick sorting of messages to specific mailboxes so it just took adding a quick rule that runs this new Applescript. So my magic combos are ctrl-T for creating the task and ctrl-R to move it out of the inbox to a reference folder.

Script

(*
Mail to Daylite Task Script
©2009 Alex Bratton <alex.bratton@lextech.com>
Based on Mail2DL script by Casper Lassenius <casper.lassenius@iki.fi>

This script is distributed as open source software
You are free to copy, modify and share parts of or the entire script, as long as you
a) Keep this notice in any modified version of the script
b) Transfer this notice to any derrivative work
c) Don’t charge money for this script or any derrivative of it

This software is provided “as is” without any warranty, explicit or implied.
The author of this software is not liable to any loss or damage of data that
may happen by installing or using it.
*)

tell application “Mail”
set AppleScript’s text item delimiters to return
set _sel to get selection
set _links to {}
repeat with curMessage in _sel
set _messageURL to “message://%3c” & curMessage’s message id & “%3e”
set end of _links to _messageURL
set curText to subject of curMessage — subject from the ToDo’s summary
set bodylength to length of (content of curMessage as string)
if bodylength > 1000 then
set bodylength to 1000
end if
set body to characters 1 through bodylength of content of curMessage
set curBody to “”
repeat with theChar in body
if contents of theChar is “‘” then
set curBody to curBody & “””
else
set curBody to curBody & theChar
end if
end repeat
set curBody to reply to of curMessage & ”
” & curBody

tell application “Daylite”
eval ”
document := (NSApplication sharedApplication) firstDayliteDocument.
objectContext := document objectContext.

creation_context := objectContext creationContext.
new_task := creation_context createObjectForEntityNamed:’Task’ addToObjectContext:true.

new_task setTitle:’” & curText & “‘.
new_task setDetails:’” & _messageURL & ”
” & curBody & “‘.
new_task addToInboxForObjectContext: objectContext.
objectContext saveChanges.”
end tell
end repeat
end tell

Edit: Here’s a link to download the script as a zip file
Add Daylite Task script

Tagged with:
 

8 Responses to “Creating Daylite Tasks From Mail App Script”

  1. John says:

    Seems great to try, but . . . no cannot find the link to download it.

  2. MiGrant says:

    Umm, call me stupid, but I can’t find the script.

  3. D says:

    Hi, I stumbled on to this looking for the very solution you created. But I don’t actually see the script. Am I missing something?

    thanks!

  4. Adrienne Szewczyk says:

    Sorry about that!

    We recently updated our website, and I must have missed the script when copying over the blog content.

    I pasted it in the blog entry above. Please let me know if you have any questions.

  5. [...] This post was mentioned on Twitter by marketcircle and James Spencer, Lextech. Lextech said: How to create #Daylite Tasks From #Mail App Script http://bit.ly/icvCX8 @marketcircle [...]

  6. Nathan says:

    Sorry, I am an AppleScript newbie and can’t get this to work.

    I tried copying the script off the site into the AppleScript Editor (Mac OS 10.6.6). When I press the Compile button, I get the following Syntax Error:

    “Expected expression, property or key form, etc. but found unknown token.”
    with the quotation marks surrounding the word “mail” in the first line of the script, “tell application Mail” highlighted.

    As Apple ScriptEditor won’t let you save the script when it can’t compile, I can’t even test it.

    Thoughts?

    Thanks!

  7. Alex Bratton says:

    There’s a known issue with the script in that it’s not handling attachments and some longer emails well. There’s an encoding error in the fscript that won’t take the input from mail completely. I haven’t had the time to dig back in and fix that — if you play with it and find a fix, please let me know.

  8. CJ says:

    Any resolution on this? The script works for plain text emails, but the emails I’d like to use it on (reminder emails sent from followupthen.com) won’t work.

    Thanks

Leave a Reply


Sign up to get enterprise app success stories

* = required field

We’re Hiring

Do you want to be part of an award-winning app development team?

iOS/Android Development Tech Team Lead - Lisle, IL

iOS/Android Mobile App Developer(s) - Lisle, IL

Check out our open positions or
contact us at careers@lextech.com.