Bike may at some point acquire row type attributes like note etc, and a style-sheet mechanism for making row type differences visible, but in the meanwhile:
here is a script for toggling single character prefixes( like >, for example) at the start of each selected line:
To test in Script Editor.app,
set the language selector at top left to JavaScript (rather than AppleScript)
copy and past the whole of the script behind the expansion triangle below,
select some lines in Bike
and click Run.
Expand disclosure triangle to view JS Source
(() => {
"use strict";
// Toggle a given prefix character in selected lines
// of Bike 1.2
// Rob Trew @2022
// Ver 0.01
// --------------------- OPTION ----------------------
// Which single-character prefix to add or clear ?
const prefixChar = ">";
// const
// prefixChar = Application("Keyboard Maestro Engine")
// .getvariable("local_PrefixChar");
// ------------ PREFIX CHARACTER TOGGLED -------------
// main :: IO ()
const main = () => {
const
bike = Application("Bike"),
doc = bike.documents.at(0);
return doc.exists() ? (() => {
const
selectedRows = doc.rows.where({
selected: true
}),
n = selectedRows.length;
return Boolean(n) ? (() => {
const [f, change] = (
selectedRows.at(0).name()
.startsWith(prefixChar)
) ? (
[dePrefixed(prefixChar), "CLEARED"]
) : [prefixed(prefixChar), "ADDED"];
return (
zipWith(row => s => row.name = s)(
selectedRows()
)(
selectedRows.name().map(f)
),
[
`${change} '${prefixChar}' prefix`,
`in ${n} selected lines.`
]
.join("\n")
);
})() : "No rows selected in Bike";
})() : "No documents open in Bike";
};
// -------------------- PREFIXES ---------------------
// prefixed :: Char -> String -> String
const prefixed = c =>
s => `${c} ${dePrefixed(c)(s)}`;
// dePrefixed :: Char -> String -> String
const dePrefixed = c =>
s => c === s[0] ? (
s.slice(" " === s[1] ? 2 : 1)
) : s;
// --------------------- GENERIC ---------------------
// zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
const zipWith = f =>
// A list constructed by zipping with a
// custom function, rather than with the
// default tuple constructor.
xs => ys => xs.map(
(x, i) => f(x)(ys[i])
).slice(
0, Math.min(xs.length, ys.length)
);
// MAIN
return main();
})();
(You can choose a different single-character prefix by editing the value of the prefixChar string constant at the top of the script)
You could certainly write something like this for TaskPaper – adaptation perhaps not directly – the Bike version is written for the JXA interface with where/whose clauses etc
I’m working on something else at the moment, but very happy to help at some point if anything is looking like a roadblock.
Instead of selecting the line after the prefix is toggled, I want to leave the text cursor at the same location that it was in before the prefix is added.
I have most of this figured out, except that my text cursor is two characters off (which makes sense, as we are adding two characters to the beginning of the line).
How do I adjust the location of the text cursor by two characters?