clenio
1
We have ⌘+0 and ⌘+9, but, i cant find a toggle one.
In my memory, this feature was present in earlier versions. Is there any way to implement this without programmer skill?
I may be wrong and/or be asking a rather stupid question … I apologize in that case.
By default the Keyboard Maestro macro here:
turns both ⌘0 and ⌘9 into toggles, but you could instead assign a 3rd key, leaving the other two unchanged.
If you want to attach the JS snippet to a key stroke using some method other than Keyboard Maestro,
( Using Scripts · TaskPaper User's Guide )
then the source code – make sure you copy all of it ( down to the line after return jxaMain();
) – is:
(() => {
'use strict';
// TASKPAPER 3 CONTEXT ----------------------------------
const tpJSContext = (editor, options) => {
// tp3Main :: () -> Either MessageString ResultString
const tp3Main = () => {
const items = editor.selection.selectedItems;
return bindLR(
items.length > 0 ? (
Right(items)
) : Left('No item(s) selected in TaskPaper 3'),
xs => {
const k = editor.isCollapsed(xs[0]) ? (
'Expanded'
) : 'Collapsed';
return (
editor['set' + k](xs),
Right(k)
);
}
);
};
// GENERIC --------------------------------------------
// Left :: a -> Either a b
const Left = x => ({
type: 'Either',
Left: x
});
// Right :: b -> Either a b
const Right = x => ({
type: 'Either',
Right: x
});
// bindLR (>>=) :: Either a -> (a -> Either b) -> Either b
const bindLR = (m, mf) =>
m.Right !== undefined ? (
mf(m.Right)
) : m;
// TP3 MAIN -------------------------------------------
return tp3Main();
};
// JXA CONTEXT-------------------------------------------
// jxaMain :: () -> Either MessageString ResultString
const jxaMain = () => {
const
ds = Application('TaskPaper')
.documents,
lrResult = bindLR(
ds.length > 0 ? (
Right(ds.at(0))
) : Left('No TP3 documents open'),
d => d.evaluate({
script: tpJSContext.toString(),
withOptions: {}
})
);
return lrResult.Right || lrResult.Left;
};
// GENERIC ----------------------------------------------
// Left :: a -> Either a b
const Left = x => ({
type: 'Either',
Left: x
});
// Right :: b -> Either a b
const Right = x => ({
type: 'Either',
Right: x
});
// bindLR (>>=) :: Either a -> (a -> Either b) -> Either b
const bindLR = (m, mf) =>
m.Right !== undefined ? (
mf(m.Right)
) : m;
// JXA MAIN ----------------------------------------------------------------
return jxaMain();
})();
3 Likes
clenio
3
Perfect. Thank you very much!
1 Like