A script for Tasks

This is a sample script to create an entry in Tasks.

This script will take the current message that you are reading in mail.app and open a window in Safari with the tasks new new task screen, the subject of the mail message is the title of the task and the body of the email is the description of the task.

<div class="codeblock"><!-- AppleScript Formatting Start -->

Open this script in a new Script Editor window.

change this to be the base path of your tasks site

property kUrlToTasks : "http://tasks.samdevore.com/"


on encodeText(thisText)
    set the acceptableCharacters to "abcdefghijklmnopqrstuvwxyz0123456789"
    set the encodedText to ""
    set the characterList to {}
    repeat with thisChar in thisText
        set thisChar to the contents of thisChar
        if thisChar is in the acceptableCharacters then
            set the end of the characterList to thisChar
        else
            set the end of the characterList to encodeChar(thisChar)
        end if
    end repeat
    return (the characterList) as string
end encodeText

this sub-routine is used to encode a character
on encodeChar(thisChar)
    set the ASCIINum to (the ASCII number thisChar)
    set the hexList to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
    set x to item ((ASCIINum div 16) + 1) of the hexList
    set y to item ((ASCIINum mod 16) + 1) of the hexList
    return ("%" & x & y) as string
end encodeChar
using terms from application "Mail"
    on perform mail action with messages theSelectedMessages
        tell application "Mail"
            if (count of theSelectedMessages) is equal to 0 then
                display dialog "Please select a message in Mail first, then run this script again."
            else if (count of theSelectedMessages) is equal to 1 then
                set eachMessage to item 1 of theSelectedMessages
                set theSource to content of eachMessage
                set theSubject to subject of eachMessage
                my createMessageWithSource(theSource, theSubject)
            else
                display dialog "Please select only one message in Mail first, then run this script again."
            end if
        end tell
    end perform mail action with messages
end using terms from

on createMessageWithSource(theSource, theSubject)
    set theUrl to kUrlToTasks & "index.php?screen=edit&taskNotes="
    
    set theUrl to theUrl & encodeText(theSource)
    set theUrl to theUrl & "&taskTitle=" & encodeText(theSubject)
    tell application "System Events"
        open location theUrl
    end tell
    
    
end createMessageWithSource

This combines really well with AppleScript keyboard shortcuts in mail.app

download