AddCurrentMailToTaskPaper

Select a message in Mac Mail. Run this script - it will make a new entry in the Inbox of Taskpaper with the subject of the email and a URL that points to the email. To use a service instead of a script, see further down.

Installation

This really is a pretty simple process, but for the sake of the AppleScript-uninitiated (that was me until about 30 mins ago ;-), I'll detail all the steps here.

  1. Install Growl, from http://growl.info/
  2. Run AppleScript Editor, from /Applications/Utilities. Select the "Preferences..." menu item. Ensure that the check-box "Show Script menu in menu bar" is checked.
  3. Copy and paste the script text from this web page (below) into the "Untitled" window in AppleScript Editor. Save this script to either the local or global scripts folder for Mail.app (~/Library/Scripts/Applications/Mail or /Library/Scripts/Applications/Mail, respectively). Call this file "AddCurrentMailToTaskPaper", or whatever else you like (e.g., "TaskPaper - Send to Inbox"). If you get a dialog box at this stage, asking you to locate the "GrowlHelperApp" application, this means that something is wrong with your Growl installation, or Growl is not currently running - check your Growl settings in System Preferences, or reinstall it as in Step 1.
  4. Run Mail.app. Ensure that the AppleScript menu is visible towards the right of your menu bar. (It has a scroll-like "S" icon.) If this menu item is not visible, revisit Step 2 above, to make sure it's enabled.
  5. Check to see that the name of the script you saved in Step 3 is in the AppleScript menu. If it isn't, try Step 3 again.
  6. Select a mail message. Then select your script's name in the AppleScript menu. If all works right, a little "Added to TaskPaper" confirmation should pop up on-screen. If you now switch applications to TaskPaper, you will see a new task item in the Inbox, with a URL which links to the original message.

Script

tell application "Mail"
    try
    set theSelection to the selection
    if the length of theSelection is less than 1 then error "One or more messages must be selected."
    repeat with theMessage in theSelection
        my importMessage(theMessage)
    end repeat
end try
end tell

on importMessage(theMessage)
tell application "Mail"
    try
        set theSubject to subject of theMessage
        set theDate to date received of theMessage
        set messageURL to "message://%3C" & (message id of theMessage) & "%3E"
        tell application "TaskPaper"
            tell front document
                tell project named "Inbox"
                    make new entry with properties {name:"- " & theSubject & " " & messageURL}
                end tell
            end tell
        end tell
    end try
end tell

tell application "GrowlHelperApp"

    set the allNotificationsList to ¬
        {"Mail to TaskPaper success"}

    set the enabledNotificationsList to ¬
        {"Mail to TaskPaper success"}

    register as application ¬
        "Mail to TaskPaper" all notifications allNotificationsList ¬
        default notifications enabledNotificationsList ¬
        icon of application "TaskPaper"

    notify with name ¬
        "Mail to TaskPaper success" title ¬
        "Added to TaskPaper" description ¬
        theSubject application name "Mail to TaskPaper"
end tell
end importMessage

Adding the script as a Service

Instead of using the above script directly, you can embed it in a Automator Service, which can then be called using the Service menu (and given an optional keyboard shortcut in System Preferences->Keyboard->Keyboard Shortcuts->Services, see end of list). The service will appear only in Mail.app (in the Mail->Services menu item) and remove the need (and space) for the Applescript menubar item. Caveat: I have only tested this in 10.6 ! To do so launch Automator and choose Service; with the new automator script choose "no input" and set the application to "Mail". From the sidebar pick the "execute an Applescript" task and drag it to the main automator window. In the AppleScript box, replace the text:

(* Your script goes here *)

with the script that follows. It's slightly different from the above, because Automator won't accept the subroutine. I've kept the Growl notification, and moved the message URL, sender, and date to the notes field for the task. You can edit the script to change how the task is created and displayed.

-- new script rewritten for automator     
tell application "Mail"
    try
        set theSelection to the selection
        if the length of theSelection is less than 1 then error "One or more messages must be selected."
        repeat with theMessage in theSelection
            set theSubject to subject of theMessage
            set theDate to date received of theMessage
            set theSender to sender of theMessage
            set messageURL to "message://%3C" & (message id of theMessage) & "%3E"
            tell application "TaskPaper"
                tell front document
                    tell project named "Inbox"
                        set newEntry to make new entry with properties {entry type:task type, text content:theSubject}
                        tell newEntry
                            make new entry with properties {entry type:note type, text content:"From " & theSender & " on " & theDate}
                            make new entry with properties {entry type:note type, text content:messageURL}
                        end tell
                    end tell
                end tell
            end tell
        end repeat
    end try
    tell application "GrowlHelperApp"
        set the allNotificationsList to ¬
            {"Mail to TaskPaper success"}
        set the enabledNotificationsList to ¬
            {"Mail to TaskPaper success"}
        register as application ¬
            "Mail to TaskPaper" all notifications allNotificationsList ¬
            default notifications enabledNotificationsList ¬
            icon of application "TaskPaper"
        notify with name ¬
            "Mail to TaskPaper success" title ¬
            "Added to TaskPaper" description ¬
            theSubject application name "Mail to TaskPaper"
    end tell
end tell