Hi all,
Here is a very simple scripting solution written in JavaScript for Automation (JXA) without any external dependencies.
Here the JXA script:
// Description: Quick entry script for TaskPaper app
var filePath = "~/gtd.taskpaper"; // Path to TaskPaper file
var appendItems = true; // If true, items will be added to the end rather than top of Inbox
function TaskPaperContextScript(editor, options) {
var outline = editor.outline;
var inbox = outline.evaluateItemPath("//Inbox")[0];
var items;
if (options.text && options.text !== "") {
items = ItemSerializer.deserializeItems(options.text, outline, ItemSerializer.TEXTMimeType);
}
if (!inbox) {
inbox = outline.createItem("Inbox:");
outline.root.insertChildrenBefore(inbox, outline.root.firstChild);
}
if (items) {
if (options.append) {
inbox.appendChildren(items);
} else {
inbox.insertChildrenBefore(items, inbox.firstChild);
}
}
}
var app = Application("System Events");
app.includeStandardAdditions = true;
var prompt = app.displayDialog("Location: " + filePath, {
withTitle: "TaskPaper – Quick Entry",
withIcon: Path("/Applications/TaskPaper.localized/TaskPaper.app/Contents/Resources/TaskPaper.icns"),
buttons: ["Cancel", "Save"],
defaultAnswer: "",
defaultButton: "Save"
})
var tp3 = Application("TaskPaper");
var isRunning = tp3.running();
var strFullPath = ObjC.unwrap($(filePath).stringByExpandingTildeInPath);
var document = tp3.open(Path(strFullPath));
document.evaluate({
script: TaskPaperContextScript.toString(),
withOptions: {text: (prompt.textReturned), append: appendItems}
});
document.save();
if (!isRunning) { tp3.quit(); }
Just set the filePath
and appendItems
variables on top of the script according to your needs. Depending on location of TaskPaper app on your machine, you would probably need to adapt path to TaskPaper icon as well (or comment this line out entirely).
Hope it will be useful for someone.