the task and any parental/ancestral context that you want will appear on the menu bar
(moving the @now tag to another line will result in the menu bar display being updated)
SCRIPT:
(to be copied and pasted into a text field in TextBar - can be tested first in something like CodeRunner.app, or in the terminal)
osascript -l JavaScript <<JXA_END 2>/dev/null
(function (intMaxParts) {
'use strict';
// ver 0.3 Requires TaskPaper 3 Preview version 166
// (FIRST LINE TAGGED WITH @NOW and optionally a path to it)
// Increase the value of intMaxParts (argument at end of script)
// to lengthen the path displayed
var intMax = intMaxParts || 99,
strQuery = '//@now[0]/ancestor-or-self::*[-' + intMax + ':]',
rgxBullet = /^- /,
strArrow = " -> ",
strTextColor = '#00FF00'; // orange: '#FFA361'. For green: '#00FF00'
// ConcatMap A FUNCTION OVER A LIST
var strStep = function (xs, f) {
return [].concat.apply([], xs.map(f));
// LIST: LINES ANCESTRAL TO FIRST @NOW-TAGGED LINE IN FRONT TP3 DOC
}(function () {
var ds = Application("TaskPaper").documents,
d = ds.length ? ds[0] : null;
return d ? d.evaluate({
script: (function (editor, options) {
return editor.itemBuffer.outline.evaluateItemPath(
options.query
).map(function (x) {
return x.body.string;
});
}).toString(),
withOptions: {
query: strQuery
}
}) : [];
}(),
// MAPPED FUNCTION: INCLUDE ITEM STRING IF NOT EMPTY,
// AND NOT ABOVE intMaxParts FROM RIGHT.
// ALSO PRUNE ANY LEADING BULLET
function (x) {
return x ? [x.replace(rgxBullet, '')] : [];
})
// CONCATENATE WITH ARROWS, DROPPING FINAL @NOW
.join(strArrow).replace(/\s*\@now\s*$/, "");
return strStep ? '<html><font style=color:' + strTextColor + ';font-family:"Menlo">' +
strStep + '</font></html>' : '❓';
})(2); // MAX NUMBER OF PATH SEGMENTS TO INCLUDE
JXA_END
Adjust the intMaxParts integer argument at the end of the script (the default 2 gives the @now line and its parent – 1 gives just the @now line – Infinity gives the whole path, other numbers give an ancestral path up to a maximum number of path segments long.
I’m not personally a user of BitBar, so I haven’t tested this, but glancing at their notes, it seems that all that is required is an (execute-enabled) bash script with a .sh extension, which returns a text.
If you save the following as an .sh file, you should be able to fine-tune it to generate the text you want.
This rough draft lists the first task which has a @now tag (any ancestral path delimited with arrows up to a maximum segment length).
To generate a different text, you can adjust the itemPath expression that is bound to the variable name strQuery, near the top of the script.
#!/bin/bash
osascript -l JavaScript <<JXA_END 2>/dev/null
(function (intMaxParts) {
'use strict';
// ver 0.3 Requires TaskPaper 3 Preview version 166
// (FIRST LINE TAGGED WITH @NOW and optionally a path to it)
// Increase the value of intMaxParts (argument at end of script)
// to lengthen the path displayed
var intMax = intMaxParts || 99,
// EDIT THE TASKPAPER 3 QUERY (itemPath) THAT YOU NEED
strQuery = '//@now[0]/ancestor-or-self::*[-' + intMax + ':]',
rgxBullet = /^- /,
strArrow = " -> ";
// ConcatMap A FUNCTION OVER A LIST
var strStep = function (xs, f) {
return [].concat.apply([], xs.map(f));
// LIST: LINES ANCESTRAL TO FIRST @NOW-TAGGED LINE IN FRONT TP3 DOC
}(function () {
var ds = Application("TaskPaper").documents,
d = ds.length ? ds[0] : null;
return d ? d.evaluate({
script: (function (editor, options) {
return editor.itemBuffer.outline.evaluateItemPath(
options.query
).map(function (x) {
return x.body.string;
});
}).toString(),
withOptions: {
query: strQuery
}
}) : [];
}(),
// MAPPED FUNCTION: INCLUDE ITEM STRING IF NOT EMPTY,
// AND NOT ABOVE intMaxParts FROM RIGHT.
// ALSO PRUNE ANY LEADING BULLET
function (x) {
return x ? [x.replace(rgxBullet, '')] : [];
})
// CONCATENATE WITH ARROWS, DROPPING FINAL @NOW
.join(strArrow).replace(/\s*\@now\s*$/, "");
return strStep ? strStep : '❓';
})(2); // MAX NUMBER OF PATH SEGMENTS TO INCLUDE
JXA_END
This is very cool! But I can’t get it to work for some reason. The script seems to produce the right result when run in terminal, but all I see in Textbar is “.” where the task should be. Any ideas? Thanks!
@dgg I’m experiencing the same thing. Any ideas @complexpoint ? Perhaps this isn’t compatible with the latest version of Taskpaper? Very cool idea though.