A script for Tasks
June 21st, 2004 | Published in AppleScript, Code Development, Tools I Use | 5 Comments
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
>>

June 21st, 2004 at 11:05 pm (#)
Very cool! I need to see if I can modify it to work w/ Camino. Although I guess it won’t kill me to use Safari every once in a while.
July 21st, 2004 at 12:08 am (#)
The script doesn’t work here. It stops with no result after the first “set theUrl”. The routine “encodetext(bob)” and “encode_text(theSubject)” seem to not work. Too bad, but good idea!
August 1st, 2004 at 11:51 am (#)
Ok this script is totally munged, I’ll fix and re-upload
August 1st, 2004 at 12:00 pm (#)
there are some funny formating issues from wp and markup, but if you use the link to create an applescript it should work fine. There are some underlines that get changed, I’ll have to change coding styles…
Sam D
August 1st, 2004 at 12:15 pm (#)
script should be cleaned up for cutting and pasting as well as via the link