Conditoned colouring (DUE in x Days)


#1

Hi there,

I’m not that into coding and stuff. But I managed to adjust a theme just the way I like it (give context different colors). But one thing I did not get to work and of which I’ not sure if that’s possible would be something like that:

For tasks that have the label @DUE(YYYY-MM-DD) depend the colouring on conditions like:

  • if those tasks are overdue make them red, bold, underlined
  • if the Date is just today color them red, bold
  • if the date is within the next 7 days, color them red
  • if the date is deeper in the future just grey them out

Any chance to get something like that implemented? If yes: how? I have a search for tasks in the next 7 days not @done and (@now or @today or @DUE <=[d] today +7d or @DUE <=[d] today) but this seems to not work as condition in the theme.less

Best
hubutz


#2

I don’t think there is (see Jesse’s explanation here). I’ve gotten around it by having an additional tag whose purpose is to make red + bold anything that’s overdue. I run a script every morning that looks at the dates on due tags and then marks them as something to do today, tomorrow, or something that’s overdue. I could probably modify that for the color scheme you’ve outlined above if you’re comfortable running a script.


#3

Thanks - might have found that myself… used the wrong terms for searching (again), need to practice more English!

If you could share that script that would be nice - might help myself a lot!


#4

Search terms in this forum can be hard — the only reason I knew where that answer was is because it was my thread. :slight_smile:

Okay, I’ve tweaked the script to create tags based on what you outlined in the main post.

@dueToday — items due today
@dueThisWeek — items due within the next 7 days (excluding items due today)
@dueFuture — items not due in the next 7 days
@OVERDUE — items which are overdue

function TaskPaperContextScript(editor, options) {
    var today = DateTime.format('today');
    var outline = editor.outline;
    
    outline.groupUndoAndChanges(function () {
        outline.evaluateItemPath('//@due <= [d] today +1 week')
            .forEach(function (each) {
      			each.setAttribute('data-dueThisWeek', '');
				each.removeAttribute('data-dueToday');
				each.removeAttribute('data-dueFuture');
    		});


        outline.evaluateItemPath('//@due = [d] today')
            .forEach(function (each) {
      			each.setAttribute('data-dueToday', '');
				each.removeAttribute('data-dueThisWeek');
				each.removeAttribute('data-dueFuture');
    		});
  		 });

        outline.evaluateItemPath('//@due < [d] today')
            .forEach(function (each) {
      			each.setAttribute('data-OVERDUE', '');
				each.removeAttribute('data-dueToday');
				each.removeAttribute('data-dueThisWeek');
				each.removeAttribute('data-dueFuture');
    		});

        outline.evaluateItemPath('//@due > [d] today +1 week')
            .forEach(function (each) {
      			each.setAttribute('data-dueFuture', '');
    		});	


}

Application("TaskPaper")
    .documents[0].evaluate({
        script: TaskPaperContextScript.toString()
    })

If anything doesn’t work quite right or you run into any problems, let me know!

tags for color coding due dates.zip (1.3 KB)


#5

Thanks a lot. I have one stupid question: what kind of script is that? I tried to paste it into Keyboard Maestro as Apple Script and assigned F2 as hotkey (for testing purposes) but it is not doing anything.

I should look into that scripting language I can follow the script text! :slight_smile:

//EDIT: when I paste it as Javascript for Automation it does not work too. I’ve extracted the .zip as well and opened that via script editor. When I press run it shows as result: undefined.


#6

Try just saving the unzipped script file and setting up your Keyboard Maestro macro like this:


#7

my setup looks exactly like yours but it’s not doing anything. Do I need to enable something in TP3? Maybe I’m just to stupid…


#8

I’m really too stupid. There was no error message so I didnt get that.

you’ve wrote “due” in your script I have “DUE” in my list - so i just changed the script et voilà! Thanks a lot!


#9

Haha, glad you figured it out! :slight_smile: