Script that add/amend/remove tags to "@dueTomorrow", "@dueToday" and "@pastDue" items when the due tag/date match "@due(yyyy-mm-dd)" format

dueRefresh” script file and KM macro available in this Github repo => Inspired by this script

This script add/amend/remove “@dueTomorrow”, “@dueToday” and “@pastDue” tags to items when @due tag/date match “@due(yyyy-mm-dd)” format.

##Script File & KM Macro

  1. This Github repo contains the script file and a Keyboard Maestro macro that triggers on Taskpaper window open or focus. Look for the scripts > dueRefresh directory.
  2. It works well when immediately chained in Keyboard Maestro to this script that convert informal dates to “yyyy-mm-dd” ISO date format.

##Theme
This theme support the “@dueTomorrow”, “@dueToday” and “@pastDue” tags styling with yellow,green and red colours as shown in the picture above.

##Style Scope


item[data-dueTomorrow] { ... }
item[data-dueToday] { ... }
item[data-pastDue] { ... }

##Script


function TaskPaperContextScript(editor, options) {
    var today = DateTime.format('today');
    var outline = editor.outline;
    
    outline.groupUndoAndChanges(function () {

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

    });
     
}

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

5 Likes