Mail to TP3 script?


#21

This is great thank you @complexpoint

I am new to TaskPaper and not a scripter so forgive me if this is very basic but after trying myself I am unable to achieve the desired modification.

By default this script produces the output:

o [sender name] [sender email] [subject] [recievedTAG(date-time)]
o [outlook link]

It really bugs me that the outlook link is on a new line and not just at the end of the original one. :slight_smile:

o [sender name] [sender email] [subject] [recievedTAG(date-time)] [outlook link]

any help on how to correct this behaviour would be greatly appreciated.

Thanks!


#22

Instead of adding the msg.link as a child of the main entry, you can append it directly:

        outline.groupUndoAndChanges(function () {
            options.messages
                .forEach(function (msg) {
                    var item = outline.createItem(
                        '- ' + [msg.sender, msg.subject]
                        .join(' ') +
                        ' @received(' + msg.received + ') ' + msg.link
                    );

                    itemInbox.appendChildren(item);
                    
                    // item.appendChildren(
                    //     outline.createItem(msg.link)
                    // );
                });

        });

#23

Thank you good Sir, much appreciated. I was digging in the wrong bit of code! Seems obvious now, clearly forgotten most of what I taught myself many moons ago.


#24

Can anyone figure out what I’m doing wrong here (using Apple Mail).
I go into mail and highlight a message
I run the script and it stops on line: var tp3 = Application("com.hogbaysoftware.TaskPaper3”), with Error -2700
I dialogue box appears in mail which says: "TaskPaper got an error: Can’t make class «class TPer».
com.hogbaysoftware.TaskPaper3, as well as com.hogbaysoftware.TaskPaper3.direct, exist, they are in my Application Scripts folder.

Any ideas what I’m doing wrong?


#25

Just a change in the Application id, I think.

If you look for the following in the script:

var tp3 = Application("com.hogbaysoftware.TaskPaper3")

you can edit it to:

var tp3 = Application("TaskPaper")

#26

I’ve made the change, the script runs. So does the moveProject script. Thanks so much for your speedy reply/help.


#27

This is fantastic, @complexpoint, thanks very much for doing this, it works great for me.

Out of curiosity, do you have any sense how hard it would be to convert the script to work with Thunderbird? It’s my preferred mail client, and I’d love the ability to have this there. I suspect this only works with applications that have a callback url scheme defined, but I’m not sure if that’s a blessing from Apple or if developers can just do that.

Thanks again!


#28

how can I activate a TP3 file to add (default file in general). if the file is not in the front and opened, the script does not add items to inbox.
thanks


#29

There might be better ways, but here’s one way to open a document from the Desktop and make it the current document. Should work in both cases where document is not yet opened, or when it is already open, but just not frontmost:

Application("TaskPaper").activate()
Application("TaskPaper").open("/Users/jessegrosjean/Desktop/test.taskpaper")

#30

Great thanks it worked (I commented the activate since it brings the window in the front)


#31

can I get some help on how to add items to the top of the document rather than at the bottom?
thanks


#32

This is in the context of sending to an Inbox project, or perhaps to a project selected from a menu ?

Or just to the top/bottom of the whole document outside a project ?

Could you post the draft you are using at the moment ?


#33

thanks
I am trying to get some updates and add them to a current open file. There is no inbox or project yet. I am trying to use various Taskpaper files inside Devonthink and use them to manage individually rather than one big doc

Current all the updates go with the script to the bottom on the document where as I want to view the most recent updates on the top.

thanks


#34

Here is a (Sierra onwards) snippet which adds three lines of text (from an options array at the foot of the script), to the start of the open document.

Is that the pattern that you need ?

(options => {
    'use strict';

    // TASKPAPER 3 CONTEXT ---------------------------------------------------
    const taskpaperContext = (editor, options) => {
        const outline = editor.outline;

        outline.groupUndoAndChanges(() =>
            outline.insertItemsBefore(
                options.itemsToAdd
                .map(x => outline.createItem(x)),
                outline.root.firstChild
            )
        )
    };

    // JXA CONTEXT------------------------------------------------------------

    // Just :: a -> Just a
    const Just = x => ({
        type: 'Maybe',
        Nothing: false,
        Just: x
    });

    // Nothing :: () -> Nothing
    const Nothing = () => ({
        type: 'Maybe',
        Nothing: true,
    });

    // bindMay (>>=) :: Maybe a -> (a -> Maybe b) -> Maybe b
    const bindMay = (mb, mf) =>
        mb.Nothing ? mb : mf(mb.Just);

    const ds = Application('TaskPaper')
        .documents;
    return bindMay(
        ds.length > 0 ? Just(ds.at(0)) : Nothing(),
        d => d.evaluate({
            script: taskpaperContext.toString(),
            withOptions: options
        })
    );
})({
    itemsToAdd: [
        'alpha',
        'beta',
        'gamma'
    ]
});


#35

thanks a lot sincerely appreciate it. Let me try and get back to you.
thanks again!
nara


#36

yes works great in that order (which are in chronological order when I add ie the latest goes to the top)
eg. on an email thread I want to capture various emails (only relevant ones) and keep filing them into a Taskpaper doc
eg…

msg-c (today)
msg-b (2 days go)
msg-a (3 days ago)

etc.

thanks again