In any case, generalizing to item paths (rather than tag names), and allowing for indented projects (as well as full-left projects) a first draft might look something like:
Expand disclosure triangle to view JS source
(() => {
"use strict";
// TaskPaper 3 focus cycled to the next item
// matching a given item path.
// Rob Trew @2022
// Ver 0.01
// --------------------- OPTIONS ---------------------
// eslint-disable-next-line quotes
const itemPath = '//project "—"';
// ---------- TASKPAPER EVALUATION CONTEXT -----------
const tp3Context = (editor, options) => {
const outline = editor.outline;
// All tasks on options.itemPath
const
cycleItems = outline.evaluateItemPath(
`${options.itemPath}`
);
// Any current focus item, and its position,
// if any, in the cycle.
const
maybeFocusedItem = editor.focusedItem,
maybePosn = null !== maybeFocusedItem ? (
cycleItems.findIndex(
x => maybeFocusedItem.id === x.id
)
) : -1;
// Zero-based index of next position in the cycle,
// and the item at that index.
const
nextIndex = (1 + maybePosn) % cycleItems.length,
nextFocusItem = cycleItems[nextIndex];
return 0 < cycleItems.length ? (
// Effect
editor.focusedItem = nextFocusItem,
// Value
nextFocusItem.bodyContentString
) : `No items with with path ${options.itemPath}`;
};
// ------------- JXA EVALUATION CONTEXT --------------
// main :: IO ()
const main = () => {
const
doc = Application("TaskPaper")
.documents.at(0);
return doc.exists() ? (
doc.evaluate({
script: `${tp3Context}`,
withOptions: {
itemPath
}
})
) : "No document open in TaskPaper.";
};
// MAIN ---
return main();
})();
On my preference for a pedantic shift from taggedItems to cycledItems, this is food for thought on the legibility (weeks or months later, or by a subsequent editor) of names in code:
For others that may be looking at the above, here is how I am using them.
Once a week, I do a weekly review of all of my tasks and projects.
During the review, I bo my best to identify the three projects that will provide the best benefits to my life, if I complete them in the forthcoming week. I mark these projects with an em dash, which makes them stand out
I do the same for three tasks, but I tag them with @today
As tasks and projects are completed, I do a mini-review and choose new ones.
During the week, I need to look at the highlighted tasks and projects, and use my intuition, or “gut instinct” to choose the one that I will focus on at any given moment.
I was looking at a list of all of them, but I found it difficult to focus and choose one.
But, I found that cycling through them one by one, allowed me to choose more intuitively. By seeing one after the other, in a cycle, my gut instinct kicks into gear. During the cycle, one always “stands out.”
The above scripts will now help me efficiently cycle through each at the touch of one macro key.
These are milestone improvements to my productivity system—I hope the above is of help to others!