Combining TaskPaper with 'Tyme' (for time session tracking)?

Updated (above) to ver 0.0.4 for compatibility with TaskPaper 3 build 167

(Slight adjustment to the scripting interface to selections)

Updated to 0.0.5 for compatibility with the release version of the TaskPaper 3 API

.bodyDisplayString -> .bodyContentString

Planning take a look at Tyme 2 (which has new API) over the weekend.

So now a good time to ask me if anyone has special requests or puzzlements :slight_smile:

1 Like

Just wanted to say thanks for doing this - really appreciated. (So useful that I’ve gone back to Tyme 1!!)

Look forward to the Tyme2 updates :slight_smile:

1 Like

I have tried to adapt the script for Tyme 2, and scripted project creation works in it, but scripted creation of tasks appears to be broken.

I’ll give an update if the maker is able to fix or shed some light on that for Tyme 2.


Got a very quick and helpful response – not broken – the type constructor just needs an extra parameter now – I’ll do something at the weekend.

Much appreciated :bow:

1 Like

Here is a first draft of a Tyme 2 version which simply toggles tracking for the item selected in the front document of TaskPaper 3.

Would you like to test it ?

Tyme 2 allows us to assign categories (clients etc) to projects, but the scripting interface doesn’t seem to give us access to that (yet ?) I would really like to get it to pick up a client tag from TaskPaper 3, and find/create the project in a matching Tyme2 category, but I think that may be out of reach, at least for the moment.

Seems to be working on my system OSX 10.11, TaskPaper 3.3 (211), Tyme2 (Version 1.3.2 (1850))

// Ver 0.003

// 0.002 stops tracking of any other task before starting tracking for this one
//          (rather than simply toggling tracking for the selected task only)
// 0.003 Updated to be unaffected by changes in TaskPaper app id

// Toggling Tyme2 tracking for the item selected in TaskPaper 3's front document

(function (dctOptions) {

    function TaskPaperContext(editor, options) {
        var item = editor

        var projects = editor.outline
            .evaluateItemPath('ancestor::project[-1]', item);

        return {
            project: projects.length ? (
            ) : (options.defaultProject || 'Miscellaneous'),
            task: item ? item.bodyContentString : undefined


    // Found or created item in a collection exposed by an app
    // E.g. a project or a task in Tyme2

    // Object -> Object -> String -> Object -> Object
    function foundOrCreated(app, oParent, strClass, dctProps) {
        'use strict';

        // elements
        var elements = oParent[
                .toLowerCase() + strClass.substr(1) + 's'

            // dctProps -> lstTests
            lstTests = Object.keys(dctProps)
            .map(function (k) {
                var dct = {};
                return dct[k] = dctProps[k], dct;
            }, {}),

            // found or created
            found = elements.whose(
                (lstTests.length > 1 ? {
                    _and: lstTests
                } : lstTests[0])

            blnFound = found.length > 0,
            elem = (blnFound ? found()[0] : app[strClass](dctProps));

        // pushed into collection if new
        return (blnFound || elements.push(elem)), elem;

    var ds = Application('TaskPaper')

        dctTP3Seln = ds.length ? ds[0].evaluate({
            script: TaskPaperContext.toString(),
            withOptions: dctOptions
        }) : undefined;

    if (dctTP3Seln && dctTP3Seln.task) {
        // TYME 2
        var Tyme2 = Application('de.lgerckens.Tyme2'),

            oTask = foundOrCreated(
                    Tyme2, Tyme2,
                    "Project", {
                        name: dctTP3Seln.project
                "Task", {
                    name: dctTP3Seln.task,
                    tasktype: 'timed'
            // Toggle tracking
            strID =,
            lstTracking = Tyme2.trackedtaskids(),
            blnTracking = lstTracking.length && lstTracking
            .indexOf(strID) !== -1;

        // pause all existing tracking
        lstTracking.forEach(function (x) {
            return Tyme2.stoptrackerfortaskid(x);

        // and start tracking for this item if required
        if (!blnTracking) {

    defaultProject: 'Miscellaneous' // for tasks not enclosed by a TP3 project

Thanks for this !

Quick update as testing now - OSX 10.11.4 (15E65), Taskpaper Version 3.2 (200), Tyme 2 1.3.1 (1841)

  • Works well - toggling timer off and on for existing tasks within existing projects
  • Also works well for new projects under Miscellaneous
  • Does create a new timed entry for new task under existing project, but for some reason doesn’t show as a new task under that project on the projects view in Tyme. Does show on the Time entries screen and turns up on the Archive screen although not marked as completed.

Will carry on testing later and also delete my archive - see what that does. :slight_smile:


Now works perfectly - I had some weird archive conflict - prob. from running Tyme 1 and Tyme 2

1 Like

Thanks for checking it !

It is working great for me. Thanks.

Hey, I’m having trouble getting the “toggle selected task” script to work. No matter what I select in the document, I get the error message telling me to select something. Any ideas why this might be happening?

Tyme2 1.3.0, TP3 3.3.1.

Ver 0.002 above is working here with:

(seems later than the copy you are running, I notice)


  • The usual first check is to make sure that copy-pasting has caught all line from start to end
  • After that, my next question might be about how you are selecting and launching the script

(I’m just placing a cursor in the relevant line - not, for example, extending the selection).

1 Like

The first thing I should note which I didn’t prior is that I am using the trial version of Tyme. Given that it’s a time-based trial (hah) I wouldn’t think there would be any major code differences, but it looks like the trial version is a slightly earlier build.

That said, the issue is that I was using the earlier version of the script. So… that’s on me.

That said, however, the newer version of the script gives me a different issue. If I focus on a task (just have my cursor in the line) it gets added to my tyme list if it’s not already there, along with the project (nice touch, btw) but the timer does not start. I’m triggering the script using Alfred.

but the timer does not start

I wonder if you are being misled by the granularity of Tyme2’s time-elapsed display (minutes rather than seconds).

It stays at 00:00 for a minute before moving to 00:01

As long as the icon at left is a red circle (rather than white triangle) the timer has started.

If you are not seeing the red timer circle, then I will be able to help you with the Tyme2 version that I am running, but a trial version really introduces too many unknowns :slight_smile:

1 Like

I’m definitely not seeing the red circle.

Yeah, I’m assuming this is an issue with the trial, then. Shame, because the only real reason to try Tyme for me was the taskpaper integration. Feel like writing a script for toggl integration? :slight_smile:

Feel like writing a script for toggl integration?

Tyme2 serves me well, thanks :slight_smile:

‘toggl’ ?
having googled that string (I don’t think you gave a link), I’m guessing that it might be this web service -, which, if it proves scriptable at all, would have to be approached by injecting JavaScript into the web page. Tricky and fragile, might well not be feasible at all.

Yes, I didn’t bother including the link to emphasize that I was kidding. I assumed it would be challenging unto infeasibility, and I wouldn’t actually ask for that much unpaid effort.

Sorry my humor was a bit too dry to be apparent! And thanks for your help and all the great scripting you do do.



Either because of newish Tyme (Tyme 2 1.5.4 (2031) or shiny new Taskpaper (Version 3.5 (275)) but now getting

“The action “Run JavaScript” encountered an error.”

Any help gratefully received as usual :slight_smile:

Midnight approaching this timezone, but I’ll take a look tomorrow evening :slight_smile:

Ah – may be a quick fix.

I’ve edited it (above) to be unaffected by a small change in the TaskPaper application id.

Ver .003

Wow - that’s almost faster than autorespond!!! :smiley:

Fixed it for me, so a LIfe Saver - thanks. (Again!)

Seems to push every task to Misc. (not sure why - assume that’s something Tyme has b0rked by changing a property name or something in their scripting. So if you get a chance to fix (ie if it’s fairly trivial) that would be great but at least I’m able to carry on tracking straight out of Taskpaper - for which many thanks again.