function TaskPaperContext(editor, options) {
let project = editor.outline.createItem('New Project:')
let root = editor.outline.root
root.appendChildren(project)
editor.focusedItem = project
editor.moveSelectionToItems(project, 0, project, 11)
}
Application('TaskPaper').documents[0].evaluate({
script: TaskPaperContext.toString()
});
So that in a case where I am searching for a project, it will first run esc key and then run above code. I am not sure if there is a way to check for this. I hope I am wrong.
Detection of that kind would have to take place in the JXA context, from which you could pass in a result to the TaskPaper context through Jesse’s options mechanism.
In the snippet below, the name blnFloat is bound to true if a window with the description field set to floating window is found, and to false if only standard windows are found.
(Note that this would need to be launched by a hotkey in something like a Keyboard Maestro ‘Execute JXA’ action – those palettes are very polite and vanish at the first hint of a TP3-significant keystroke, or transfer of focus to another app, like Script Editor or Atom.
(() => {
'use strict';
const main = () => {
const tp3Context = (editor, options) => {
const blnPaletteFound = options.paletteFound;
return 'Hello world !';
}
// standardSEAdditions :: () -> Application
const standardSEAdditions = () =>
Object.assign(Application('System Events'), {
includeStandardAdditions: true
});
const
ds = Application('TaskPaper')
.documents,
lrResult = bindLR(
ds.length > 0 ? (
Right(ds.at(0))
) : Left('No TaskPaper documents open'),
d => {
const
// DETECTING A FLOATING WINDOW
// e.g. a `Go to Project` palette
sa = standardSEAdditions(),
proc = sa.applicationProcesses.where({
name: 'TaskPaper'
}).at(0),
blnFloat = 0 < proc.windows.where({
description: 'floating window'
}).length;
return Right(d.evaluate({
script: tp3Context.toString(),
withOptions: {
optionName: 'someValue',
paletteFound: blnFloat
}
}));
}
);
return lrResult.Left || (
lrResult.Right
);
};
// GENERIC FUNCTIONS ----------------------------
// https://github.com/RobTrew/prelude-jxa
// 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) =>
undefined !== m.Left ? (
m
) : mf(m.Right);
// MAIN ---
return main();
})();