What's the latest on "Quick Entry" solutions for TaskPaper 3?

The action has an abbreviation set to ‘ap’. For the first time, have TaskPaper 3 open to the file with your projects. Open the Launchbar window (cmd-space for me), type ap, hit enter on the selection that says ‘TaskPaper - Add to Project’, type in the task description with any tags you want, press enter. It will then show a list of projects to add it to. Select one and it will be added to it. After it has saved the file location with the first activation, you do not have to have TaskPaper open for subsequent additions.

If it doesn’t show up on Launchbar’s Actions list, it most likely needs to rebuild it’s indexes. Right click on LaunchBar and select the menu Index → Update Index → All Rules. It should be accessible after that. Make sure the file is located here: ~/Library/Application Support/LaunchBar/Actions/TaskPaper - Add Project.lbaction.

2 Likes

It seems to work now. I believe it needed to be indexed. Thanks!

it does not show on LB’s Action list. rebuild index, reinstall LB… it doesn’t work.

is it LB’s Problem?

Sorry, I didn’t see this question. Yes, it would be LB problem. For some reason it isn’t indexing the action. You’ll have to ask on their forum. Good luck. Very slow help there.

One of the reasons I’m considering moving back to Alfred…

Hi all,

Here is a very simple scripting solution written in JavaScript for Automation (JXA) without any external dependencies.

Screenshot 2020-05-06 at 16.45.44

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.

2 Likes

Thank you. This is very useful. I made a Keyboard Maestro macro with this script and it works great. The only thing I had to change was the path to the TaskPaper icon.

macosxguru

1 Like

I like this a lot! Thanks!

It looks like the entry is entered as a note. Is it easy to preface the entry with a dash and a space?
(example: Entry becomes - Entry)

Figured it out. If you change:

    withOptions: {text: (prompt.textReturned), append: appendItems}

to:

    withOptions: {text: ("- " + prompt.textReturned), append: appendItems}

…it becomes a task.

By the way, I would suggest changing:

    var inbox = outline.evaluateItemPath("//Inbox")[0];

to:

    var inbox = outline.evaluateItemPath("//Inbox:")[0];

…otherwise, it will find the word inbox anywhere in the document and add the entry under it.

@Jim Thank you for your suggestions.

I often add notes to my Inbox, so I just type - Task to add a task or enter Note to add a note.

If you want to be more precise, you may use something like

var inbox = outline.evaluateItemPath("//@type=project and @text matches[s] ^Inbox:")[0];

Interesting. I have never used quick entry to enter a note. Something to consider.

Thank you!

•••

By the way—when I use this script, I notice that if TaskPaper is not initially running, the script quits it after the entry.

If I want to remove that functionality, do I just delete these two lines?

var isRunning = tp3.running();
if (!isRunning) { tp3.quit(); }

Yes, exactly.

Thank you. I am still a little rough with my JavaScript, so I appreciate studying and using your code. Kudos!

I’ve created an Alfred Workflow based on the script from this post:

TaskPaper.alfredworkflow.zip (56.9 KB)

1 Like

Added to Wiki

Thanks @saf-dmitry for the original script and @Jim for the tweaks. Two questions:

  1. I too created a KM macro to run this one for me, but with both running the script from KM and Script Editor, after execution (or during) it brings Taskpaper to the foreground - any idea on how to have this quick entry in the background?
  2. Do either of you know how to get this working with a KM variable for the path? I’d like to add some logic for changing the path based on work or home taskpaper lists and then pass the path variable to the script. I stole the following from @complexpoint’s script, but I kept on getting an “The document “Test.taskpaper” could not be opened. The file doesn’t exist.” error from Taskpaper that the file was not found, even though the file and path are correct.
var kmVars = Application("Keyboard Maestro Engine")
    .variables;

var filePath = kmVars.pathVariable.value(); // Path to TaskPaper file
...

I can’t remember if the Keyboard Maestro osascript interface changed at any point, but the usual way to read a value for a KM variable name would be with:

.getvariable(variableName)

e.g.

(() => {
    "use strict";

    const main = () => {
        const kme = Application("Keyboard Maestro Engine");

        const pathString = kme.getvariable("pathVariable");

        return pathString;
    };

    // --------------------- GENERIC ---------------------

    return main();
})();

Odd. When I run it from Keyboard Maestro, TaskPaper stays in the background.

Here is the version of the script that I am running, on the chance that it helps:

var filePath = "~/Library/Mobile Documents/iCloud~is~workflow~my~workflows/Documents/Focus.txt"; // 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("//@type=project and @text matches[s] ^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("Capture what has your attention:", {
   withTitle: "Ubiquitous Capture Tool",
    withIcon: Path("/Users/jim/—ƒ—/Icons/TaskPaper3.icns"),
    buttons: ["Cancel", "Capture"],
    defaultAnswer: "",
    defaultButton: "Capture"
})

var tp3 = Application("TaskPaper");

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();

Hey @complexpoint thanks for the help, although I get the same error as before. Not sure what the issue is there. Perhaps it’s elsewhere in the script then

Thanks @Jim. So what I actually noticed with mine is that it doesn’t bring it to the front per se, but rather if taskpaper is minimised it’ll unminimise it and then which back to whatever app you were working in.

Not sure if this is the same behaviour for you and your script (haven’t had a chance to try it yet), but either way an easy fix for me is to keep Taskpaper in full screen in another desktop