Is there a way to script opening new tabs with specific projects focused?

Since I am used to navigating tabs in Safari, I am starting to use same document tabs (⌥⌘N) to quickly switch from focused project to focused project, etc., tab by tab. Once I have the tabs set up, the workflow is solid for me.

What I want to do is make a script to set up a set of tabs, each with a specific project focused.

Right now, I need to open a new tab of the same document (⌥⌘N), then focus the specific project for that tab, and repeat this for each desired project.

Is there a way to do this in AppleScript or JavaScript?

My desired projects for this are:

  • Performance Tracker → 9/25 — 10/1:
  • Links:
  • Arrivals:
  • Now:

Can’t immediately see public API for tab creation, and I think I’m being clumsy in my attempts to obtain values from the

.getOutlineEditors()

and

.getOutlineEditorsForOutline(outline)

methods.

Perhaps a question for @jesse when he gets back : )

1 Like

For a degree of tab reading, of course, there is always this kind of thing:

Expand disclosure triangle to view JS source
(() => {
    "use strict";

    const
        se = Application("System Events"),
        tp = se.applicationProcesses.where({
            name: "TaskPaper"
        }).at(0);

    return tp.exists() ? (
        tp.windows.at(0)
        .tabGroups.at(0)
        .radioButtons.name()
    ) : "TaskPaper not running.";
})();
1 Like

I don’t think a TaskPaper specific API exists. Instead I would use System Events to call the File > New Tab menu item if needed.

Those methods are class methods on OutlineEditor and can be called like this:

function TaskPaperContextScript(editor, options) {
	let editors = OutlineEditor.getOutlineEditors()
	for (var i = 0; i < editors.length; i++) {
		let editor = editors[i]
		...
	}
}

Application("TaskPaper").documents[0].evaluate({
  script: TaskPaperContextScript.toString()
});

I think to get such a script working you would need to:

  1. Find and count TaskPaper top level projects
  2. Exit out of that TaskPaperContext and use AppleScript to call File > New Tab once for each project
  3. Enter back into TaskPaper context and use OutlineEditor.getOutlineEditors() to get each editor and focus it into projects in order.

Also note that TaskPaper’s state restoration is restoring tab state for you. If you just leave your TaskPaper document open when you quit then you shouldn’t have to rebuild tabs each time, just manually create once and then you should be done.

3 Likes

Got it. Thanks !

1 Like

Thanks all!

I ended up making the following in Keyboard Maestro. It works well. I think that I was caught up in trying to do it all in one script.

4 Likes