Hello,

I hacked together a script with C & P from various sources which fills the kGTD inbox from mail.app using MailActOn. My approach is to follow http://indev.ca/MailActOnTips.html and call mail2KGTD on Ctrl-1 (Action), so I have a reference in Mail.app what was taken over by kGTD (Mail tagged as action).

A nice enhancement would be to tell Mail.app from OmniOutliner on task completition to tag the mail as done. I do it by hand at the moment, but have to maintain two lists then.

If anyone has an idea how to link the actual email within OmniOutliner (so one could click in a button in kGTD and the referenced email pops up in Mail.app), please inform.

Please note that I have absolutely no knowledge in AppleScript. The script works for me.

Script mail2KGTD:

using terms from application "Mail"
on perform mail action with messages allMessages
    try
        my generateItems(allMessages)
    on error theError number theNumber from theOffender
        beep
        --          display alert "Error " & theNumber & " occurred" message theError as critical buttons {"OK"} default button 1 giving up after 15
    end try
end perform mail action with messages
end using terms from

on run
tell application "Mail"
    if (count of selected messages of message viewer 1) is 0 then
        display alert "No messages selected" message "Please select some messages to export or click 'Reset' to set new defaults" buttons {"Reset", "OK"} default button 2 giving up after 15
        copy result as list to {theButton}
    else
        set allMessages to selected messages of message viewer 1
        my generateItems(allMessages)
    end if
end tell
end run

on generateItems(allMessages)
tell application "Mail"
    repeat with i from 1 to number of items in allMessages
        set curMessage to item i of allMessages
        set curText to reply to of curMessage & ", " & subject of curMessage
        set curBody to content of curMessage
        set curSubject to subject of curMessage
        set curSender to sender of curMessage
        set theHeaders to all headers of curMessage
        set ScriptsPath to (((path to library folder from user domain) as string) & ("Scripts:Applications:OmniOutliner Pro:Kinkless:"))
        set ReadPath to ScriptsPath & "kgtdpath.txt"

        set KGTDPathFile to open for access file ReadPath
        set ThisDocumentPath to read KGTDPathFile
        close access KGTDPathFile

        tell application "OmniOutliner Professional"

            set ThisDocument to (first document whose path is ThisDocumentPath)

            try
                get ThisDocument
            on error
                open with results ThisDocumentPath
                set ThisDocument to (first document whose path is ThisDocumentPath)
            end try

            tell ThisDocument
                set InboxSection to (first section whose note contains "meta_inbox")
                set TheTopic to curSender & ": " & curSubject
                make new row at beginning of rows of InboxSection with properties {topic:TheTopic, note:curBody}
            end tell
        end tell

    end repeat
end tell
end generateItems

bex's picture

From the looks of it, the linkage is possible

It appears that you could mark the id number of the mail message in the row, and come back to it.

That will require a place to save the id number, and a change to the sync code to check for that on completion of the item.

Can you give an example of when you are using this script? Are you using primarily for waiting fors? or what?

thanks,

bex

cg, this script is great!

cg, this script is great! Thanks for writing & posting it!

cg's picture

Thanks,

but honestly I must say that I did write maybe 2 or 3 lines of this script. The rest ist from mail2ical and the Quicksilver action coming with kGTD.

cg

cg's picture

Usage example

Hi,

Before using kGTD I used MailActOn similar as shown in the tips - page (see original post for URL) since most of my action items come in by email.

Basically I added on keycombo Ctrl-1 an action - tag and had an intelligent folder to show me all mails with an action - tag. Now I am using kGTD and want and should have only one action list, so I am now adding action items coming in by email with the mail2KGTD - script to my kGTD inbox and add context and project there. Also the mail gets colored red when added to kGTD (via MailActOn).

On my wishlist is the following: When I change the item coming in from Mail.app and sync, the sync - script tells Mail.app about the change. Then I could e.G. color the mail green when it is completed or yellow when I change the context to waiting-for.

Also normally I want to answer the original mail, so it would be more handy to get a reply - window with the original mail already cited, all CCs at hand etc. from within OmniOutliner.

One way (I don’t know anything about AppleScript) could be to add a property “script” to kGTD items, which names a script to be called on every sync-action with some relevant item data, e.G. status, context, mail-id etc.

Regards, Christoph


Sorry admin,i tested your blog:)

zxxsdjisif4244243fbsd454vnmzxc187


bex's picture

The flesh is willing ...

But the mind is weak. I regret that I do not have the applescript knowledge (nor the time as I am trying to get myself moved to DE) to write this.

If I could see some example code that would open a message in mail.app by ID number, I think the rest is trivial. I however am embarrassed to say I cannot figure out how to do that.

Once that is in place it is fairly easy (or so I would love to believe) to

1 - Modify sync to “do the right thing” on Mail-items (so denoted by having “Mail: ID - body” as the note??)

2 - Add a “Reply to this mail-item” button that would be used to open the message for reply in mail.app

Any ideas?

Sorry admin,i tested your blog:)

zxxsdjisif4244243fbsd454vnmzxc187


bex's picture

The flesh is willing ...

But the mind is weak. I regret that I do not have the applescript knowledge (nor the time as I am trying to get myself moved to DE) to write this.

If I could see some example code that would open a message in mail.app by ID number, I think the rest is trivial. I however am embarrassed to say I cannot figure out how to do that.

Once that is in place it is fairly easy (or so I would love to believe) to

1 - Modify sync to “do the right thing” on Mail-items (so denoted by having “Mail: ID - body” as the note??)

2 - Add a “Reply to this mail-item” button that would be used to open the message for reply in mail.app

Any ideas?

bex's picture

Here is a try at a solution (partial)

Okies,

Here is a hack job if I ever saw one:

This is the “new” mail2kgtd script. Put this in your “Mail Act On” and smoke it.

—-mail2kgtd—-
using terms from application “Mail”
on perform mail action with messages allMessages
try
my generateItems(allMessages)
on error theError number theNumber from theOffender
beep
— display alert “Error ” & theNumber & ” occurred” message theError as critical buttons {“OK”} default button 1 giving up after 15
end try
end perform mail action with messages
end using terms from

on run
tell application “Mail”
if (count of selected messages of message viewer 1) is 0 then
display alert “No messages selected” message “Please select some messages to export or click ‘Reset’ to set new defaults” buttons {“Reset”, “OK”} default button 2 giving up after 15
copy result as list to {theButton}
else
set allMessages to selected messages of message viewer 1
my generateItems(allMessages)
end if
end tell
end run

on generateItems(allMessages)
tell application “Mail”
repeat with i from 1 to number of items in allMessages
set curMessage to item i of allMessages
set curText to reply to of curMessage & “, ” & subject of curMessage
set curID to message id of curMessage
set curBody to content of curMessage
set curSubject to subject of curMessage
set curSender to sender of curMessage
set theHeaders to all headers of curMessage
set ScriptsPath to (((path to library folder from user domain) as string) & (“Scripts:Applications:OmniOutliner Pro:Kinkless:”))
set ReadPath to ScriptsPath & “kgtdpath.txt”

set KGTDPathFile to open for access file ReadPath
set ThisDocumentPath to read KGTDPathFile
close access KGTDPathFile

tell application “OmniOutliner Professional”

set ThisDocument to (first document whose path is ThisDocumentPath)

try
get ThisDocument
on error
open with results ThisDocumentPath
set ThisDocument to (first document whose path is ThisDocumentPath)
end try

tell ThisDocument
set InboxSection to (first section whose note contains “meta_inbox”)
set TheTopic to curSender & “: ” & curSubject
set TheNote to curBody & “
” & curID
make new row at beginning of rows of InboxSection with properties {topic:TheTopic, note:TheNote}
end tell
end tell

end repeat
end tell
end generateItems
—-end mail2kgtd—-

(For those of you following along, the only real change is that the last line of the note is now the Message ID)

Well more like, have a button bound to use it from Mail Act On (or your favorite button binder). This script needs to be called right before or right after a refile command:

Rule Act-On: t | Make a “todo” in KGTD
Condition: Every Message
Perform: Move Message to Folder “KGTD To Do”
Run Script mail2kgtd

Don’t forget to create the folder “KGTD To Do”. If you want a different folder name, fix the hard-codings in the script please.

Secondly, add the “Show Mail” script to ~/Library/Scripts/Applications/OmniOutliner Pro/Kinkless/. This script can (and should) be added to your tool bar.

—-Show Mail—-
(*

This mess by Brian Exelbierd - bex@pobox.com
Feel free to copy :D

This file, in conjunction with the modified mail2kgtd script allows KGTD to be “mail” aware.

“Kinkless GTD” http://kinkless.com/ is Copyright 2005 Ethan Schoonover - e@ejas.net

This file is NOT part of “Kinkless GTD”, so don’t blame Ethan!

*)
tell application “OmniOutliner Professional”
set ThisDocument to front document of application “OmniOutliner Professional”
set mailID to last paragraph of note of selected row of ThisDocument as string
set found to 0

tell application “Mail”
repeat with a in accounts
try
set x to (every message of mailbox named “KGTD To Do” of account (name of a) whose message id is mailID)
repeat with f in x
activate
open f
set found to 1
end repeat
end try
end repeat
end tell

if found is 0 then
display alert “I could not find the message, sorry.”
end if

end tell
—-end Show Mail—-

Here is how it all goes together.

The show mail script copies the email data over into KGTD and saves the message-ID of the mail as the last paragraph the note. You can do whatever you want to the entry, just don’t move the Message-ID from being the last paragraph.

When you are ready to get back to the original message, just select the row and click the “Show Mail” button. If the planets are in the proper alignment, you should get your mail message front and center.

Let me know if anyone is brave enough to try this please. Simple testing on my side has been successful.

Thanks,

bex

Good, but needs some error checking

Thanks for the extensive write-up!
The only improvement I would suggest is (a) in “mail2kgtd”, when writing the message-id, use the following syntax:


set theNote to curBody & "
Message-ID: " & msgid

(b) in the “Show Mail” script, do a simple presence check for “Message-ID: ” to make sure that that “last line” of the selected note actually contains a message id. Something like this (**untested**):

set mailID to last paragraph of note of selected row of ThisDocument as string
if word 1 of mailID is not "Message-ID:" then
display alert "This item has no associated message."
end if
set mailID to word 2 of mailID

Otherwise, if the user runs this script on a note without an embedded message-id, then it’ll walk through the KGTD To Do folder looking for a message that it’ll never find.

Alan (or anyone), where in

Alan (or anyone), where in the script would I put the lines for ShowMail? I’m now AppleScripter…

Backgammon games

Adding icon on OmbiOutliner Toolbar

Thanks for the excellent and useful script.

One note: when you say “This script can (and should) be added to your tool bar.” it might not be immediately obvious to others how to actually do this. I found it to be really simple, actually: when you save scripts in ~/Library/Scripts/Applications/OmniOutliner Pro/Kinkless/ and then customize the OmniOutliner toolbar, they automagically appear in the collection of icons you can drag onto the toolbar.

Jennifer's picture

can't get icons to show up...

…even after doing this. they don’t appear in my collection of icons that i can drag to the toolbar.

any idea why?

jennifer

Jennifer's picture

oops

nevermind…i didn’t scroll down far enough. found it. but alas the Show Mail script doesn’t work. ;)

jennifer

Free download backgammon

It seems like OmniOutliner

It seems like OmniOutliner is changing message id (130483945@something) to an email address which is breaking the show mail script…

Agreed, I always get "I

Agreed, I always get “I could not find the message, sorry.” on clicking my Show Mail button.

My Message IDs look like this:

20060309034105.22153.qmail@uweb01.logjamming.com

URLs

I think I’ve found the problem. If OO is set to automagically make URL’s clickable, it will munge the Message ID into a link. When you get the note in applescript, all links are replaced with “?” characters. You can work around this by turning off the link magic in OO.

It’s too bad that OO can’t return the original text in applescript after it has munged a link. Is that a bug in OO?

Jennifer's picture

so how do you change that URL setting??

how do you turn off the “link magic in OO,” please??

j.

Nik's picture

Here’s an alternate script

Here’s an alternate script to handle the same thing: Send selected messages to kGTD

Pretty similar idea, it just takes the selected messages (yeah, it can handle more than one) and passes them on to kGTD’s inbox, including the whole message and select headers (subject, to, from, date sent) as a note.

I prefer this behavior to the linking option, because then I’m free to delete the email but I won’t lose context for the message, since it’s all in the notes field.

As with the other provided script, it does NOT parse the subject to pass in a project or anything else. That’s a neat idea though, and could probably be handled with a mail rule to make it wholly automatic.

This script also works with the newer version of kGTD which no longer gives you the kgtdpath.txt file.

Just drop this into ~/Library/Scripts/Application/Mail/ and it can be run from the scripts menu while browsing your email. It could also be triggered by LaunchBar/Quicksilver/Butler. This doesn’t work with Mail Act On, but I imagine someone familiar with that program (Bex?) might be able to modify it appropriately.

Nik: Improving kGTD a Script at a Time


Nik's picture

I just updated the script.

I just updated the script. It now does, indeed, pick up a link for the selected emails and adds it. I need to add rule support so it can work automatically and with Mail Act-On.

The link is problematic, however, because filing the message destroys the emlx link. However, it will add links to messages from ANY mailbox (not just a hard-coded KGTD Tasks mailbox). It’ll also handle a lack of links gracefully rather than create a false link. (It does a spotlight search for the message to find the emlx link file.)


Nik's picture

Okay, there we go. It now

Okay, there we go. It now works as a rule. Download from my iDisk.


Jennifer's picture

I couldn’t figure out

I couldn’t figure out which file to use from your iDisk - I want the MailActOn one.

Please let me know…

(I was using kGTD and Act-On but then upgraded OOP and now it doesn’t work, sigh….)

Jennifer


Torben's picture

Thanks - It works

Thanks - It works great.

Although I can’t get it to work as a rule. The script runs fine but the mail that gets copied to my kgtd inbox is the mail that is currently selected and not the new mail I just recieved.

Is there a solution for this ?


Accollon's picture

LInk is no longer working,

LInk is no longer working, would love to have this script so if there is any way I can get a copy please let me know.


Mario.Batz@cern.ch's picture

Mario@CERN Hi, I love to

Mario@CERN

Hi,

I love to use this script with kGTD. Very useful to put your stuff into one Inbox only.

Recently I came about a disavantage, i.e. that the email headers are not always explicit enough to attribut the right context and project in kGTD without opening the mail again.

Would there be a way to e.g. bring up a window and enter a comment or attrimbute a context/project when sending the email from mail to kGTD?

this way with having opened the email once it is done. Otherwise, I more and more get the feeling that I sort of put the item into IN again. Not that nice.


Peter Nigrini's picture

does anyone still have this

does anyone still have this scrips. The links are all broken. And if it isn’t too much to ask, is it still working?

Thanks

p


Peter Nigrini's picture

OK so I feel like an ass. A

OK so I feel like an ass. A bit more looking is all it took. If others are wondering, Nik has a bunch of “Crappy Software” here.

http://inik.net/taxonomy_menu/2/6

Nik, your crappy is just fine for me.

Thanks

p


Post new comment

The content of this field is kept private and will not be shown publicly.
  • You can use Markdown syntax to format and style the text.
  • Each email address will be obfuscated in a human readble fashion or (if JavaScript is enabled) replaced with a spamproof clickable link.
  • Images can be added to this post.

More information about formatting options

Captcha Image: you will need to recognize the text in it.
Please type in the letters/numbers that are shown in the image above.