Custom Workflow Requiring Scripting

The workflow I am trying to achieve using JXA–

  • Use TaskPaper to manage a task list (Tasks.txt) using tags like @now, @today, @1, @2, etc.).
  • A Keyboard Maestro hotkey to toggle the visibility of a couple of new, separate Taskpaper windows that shows only the items that I want to see in each window (using TaskPaper’s built-in search terms). When I click the hotkey the next time, it closes the new windows and shows me only the original window.

Some of the issues I’m currently struggling with:

  1. in JXA, how to select, a specific Taskpaper Window (since I can have several open at the same time, all with the same name, ‘Tasks.txt’). How to close a specific window. How to hide a specific window.
  2. how to use JXA to manipulate the TaskPaper GUI so that I can hide the Sidebar

Would be happy to have any help with this. Thanks!

Hey Roymene,

I hope that you are having a good day today and that you already found an answer to this posted question. I think that you are not getting feedback because it is very difficult to understand what you are trying to do.

What do you mean with that? Do you want to copy the subset of tasks into a new file and then do what you want to do?

You can already do that with some of the tags options within TaskPaper.

If I am not following you, please let me know and maybe someone can help. I am not good at scripting, but I can point you to a good script to get started.

Dear Victor - thank you for the feedback. You are right – my post is not easy to understand. Sorry about that! Perhaps I’ll try to edit it to make it more understandable. I am new to support forums …

What I am hoping to do is:
Use a hotkey to bring up a NEW TaskPaper window (not a new document) with a different “view” of the document, using the search-terms features that TaskPaper provides. Currently using Keyboard Maestro.

I am new to scripting, and currently having the following problems with JXA:

  • how to distinguish between the different open TaskPaper windows in JXA. In my case, they are all titled/named “Tasks.txt”


To distinguish between documents, you may need to use documents[0], documents[1], etc.

Here is a script that will activate (the already opened) Tasks.txt, open a new view with the sidebar hidden, and search for @important tagged items that are not @done. I hope that helps!

menuItemClick("TaskPaper", ['Window', 'Tasks.txt'])
menuItemClick("TaskPaper", ['File', 'New Window'])
menuItemClick("TaskPaper", ['View', 'Hide Sidebar'])

function menuItemClick(strAppName, lstMenuPath) {
    var oApp = Application(strAppName),
        lngChain = lstMenuPath.length,
        blnResult = false;

    if (lngChain > 1) {

        var appSE = Application("System Events"),
            lstApps = appSE.processes.where({
                name: strAppName
            procApp = lstApps.length ? lstApps[0] : null;

        if (procApp) {
            var strMenu = lstMenuPath[0],
                fnMenu = procApp.menuBars[0].menus.byName(strMenu),
                lngLast = lngChain - 1;

            for (var i = 1; i < lngLast; i++) {
                strMenu = lstMenuPath[i];
                fnMenu = fnMenu.menuItems[strMenu].menus[strMenu];

            blnResult = true;
    return blnResult;

function TaskPaperContextScript(editor, itemPathFilter) {
  editor.itemPathFilter = itemPathFilter

  script: TaskPaperContextScript.toString(),
  withOptions: "@important and not @done"
1 Like

Thank you Jim. This is indeed very helpful, especially the menuItemClick function.

A couple of problems though:

documents[0], documents[1], etc. only refer to the actual documents, and not to the windows that are open. I am trying to distinguish between windows. For example, I will have 4 different windows with the same document open (i.e. Tasks.txt), but I can’t seem to distinguish between these windows. I’ve looked at this link but it hasn’t help me figure out the problem.

throws an error when the Sidebar is already hidden. Do you know a way to check the Sidebar status in JXA. If not, not to worry, I can try/catch the error, but I thought I’d see if there was something I’m missing …

Perhaps try windows[0], windows[1], etc.

In JXA? No. (I am still a JavaScript beginner—Jesse and ComplexPoint are the experts here)

In AppleScript:

tell application "TaskPaper" to activate
tell application "System Events" to tell process "TaskPaper"
	if menu item "Hide Sidebar" of menu "View" of menu bar 1 exists then
		click menu item "Hide Sidebar" of menu "View" of menu bar 1
	end if
end tell