Hi all,
i am by no means a geek, i have no experience with applescript and coding. But one of the things which i want to do was to pick up an email from mail.app, set it to my default context, and allow me to create the description, or set it to the default “tricks” sender&title;.
Also i wanted to add a link to the original message from within mail (same as yojimbo link or kind of i guess).
So i wasted a fair bit of my time and i managed to come up with the following script.
NOTE: this was heavily borrowed from the original “tricks” section within TRACKS….
tell application "Mail"
set theSelection to the selection
if the length of theSelection is less than 1 then
display dialog "One or more messages must be selected." buttons {"OK"} default button 1 with icon caution
else
repeat with theMessage in theSelection
my importMessage(theMessage)
end repeat
end if
end tell
on importMessage(theMessage)
-- Get the info from the email message
tell application "Mail"
try
set theSender to the sender of theMessage
set theSubject to subject of theMessage
if theSubject is equal to "" then set theSubject to emptySubject
-- Construct the description string from the email info
display dialog "Description of action for this email:" default answer ""
set myDesc to text returned of the result
if the length of myDesc is less than 1 then
set myDesc to "Email " & theSender & " about " & theSubject
-- Trim the string to 100 characters otherwise it won't validate
if length of myDesc > 100 then
set myDesc to characters 1 thru 100 of myDesc
end if
end if
end try
display dialog "message" default answer ""
set _mes to text returned of the result
set _sel to get selection
set _links to {}
repeat with _msg in _sel
set _messageURL to _mes & "message" & _mes & ":message://<" & _msg's message id & ">"
set end of _links to _messageURL
end repeat
end tell
-- Now send all that info to Tracks
-- Edit the URL of your Tracks installation if necessary"
set myUsername to "place_your_name_here"
set myToken to "your_token"
set myContextID to 1
set myNotes to _messageURL
tell application "http://0.0.0.0:3000/backend/api"
set returnValue to call xmlrpc {method name:"NewTodo", parameters:{myUsername, myToken, myContextID, myDesc, myNotes}}
end tell
(* Growl support - comment out or delete this section if
you don't have Growl *)
tell application "GrowlHelperApp"
set the allNotificationsList to ¬
{"Tracks Notification"}
-- Make a list of the notifications
-- that will be enabled by default.
-- Those not enabled by default can be enabled later
-- in the 'Applications' tab of the growl prefpane.
set the enabledNotificationsList to ¬
{"Tracks Notification"}
-- Register our script with growl.
-- You can optionally (as here) set a default icon
-- for this script's notifications.
register as application ¬
"Tracks Applescript" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Script Editor"
set growlDescription to "Action with ID " & returnValue & " was created."
notify with name "Tracks Notification" title "New action sent to Tracks" description growlDescription application name "Tracks Applescript" icon of application "Script Editor.app"
end tell
(* End of Growl section *)
end importMessage
Well, kudos to those who wrote and came up with most of this code and i hope you guys could add ![]()
Thanks
Fabs
