I call it my Weekly Review script. But that might not help others when browsing the wiki.
I use this script for my GTD Weekly Review. The Weekly Review is part of the Getting Things Done productivity practice.
I use the script to focus in on each individual line in my TaskPaper document, so that I can review each one individually (making changes, adding tags, start/due dates, etc.).
This script (now) allows me to move from the reviewed item to the next item flawlessly. I am so happy!
Here, FWIW is a variation of your script which aims to skip any blank lines.
(My files seem to be full of them)
Expand disclosure triangle to view JS Source
(() => {
"use strict";
// Move focus to next non-empty line in file.
// Starts with selected line, if there is no focus.
// (Focus cleared if no more lines remain)
// Rob Trew @2021
// Ver 0.04
// ------------------- JXA CONTEXT -------------------
const main = () => {
const docs = Application("TaskPaper").documents;
return 0 < docs.length ? (
docs.at(0).evaluate({
script: `${TaskPaperContext}`
})
) : "No documents open in TaskPaper";
};
// ---------------- TASKPAPER CONTEXT ----------------
const TaskPaperContext = editor => {
const tp3Main = () => (
editor.focusedItem = (
null === editor.focusedItem ? (
editor.selection.startItem
) : Boolean(editor.focusedItem.nextBranch) ? (
nextNonEmpty(
editor.focusedItem
)
) : null
),
editor.focusedItem ? (
editor.focusedItem.bodyContentString
) : ""
);
// ------------- NEXT NON-EMPTY LINE -------------
// nextNonEmpty :: Item -> Item
const nextNonEmpty = item =>
until(
x => Boolean(x.bodyString.trim()) || (
null === x.nextItem
)
)(
x => x.nextItem
)(
item.nextItem
);
// ------------------- GENERIC -------------------
// until :: (a -> Bool) -> (a -> a) -> a -> a
const until = p =>
// The value resulting from repeated applications
// of f to the seed value x, terminating when
// that result returns true for the predicate p.
f => x => {
let v = x;
while (!p(v)) {
v = f(v);
}
return v;
};
return tp3Main();
};
// MAIN ---
return main();
})();