OMF Script to create task from current item

Good morning.

I’m sorry if this has been covered. I looked but there are a lot of very common words in my question.

Have any of you seen an Omnifocus script that will take the currently highlighted task, create a new task (preferably in the next actions project) with the same name and the link to the original item in the notes field?

Use case: I want to be able to review projects, deliverables, and next steps for all projects and then create tasks in the next actions for what I’m going to do that week. Then I want to be able to order them in the Next Actions project by that week’s priorities. I need this partially because my database is huge and I like the way I currently order my projects and folders, but it makes it difficult to order this week’s work in the order I want to do it. Very little of my work is date driven.

Oh… And I have absolutely no scripting ability. :)

FWIW, here is a rough draft. You can paste it in Script Editor and execute it. Set language tab to Javascript.

(() => {
    'use strict';

    // OMNI JS CODE ---------------------------------------
    const omniJSContext = () => {
        // main :: IO ()
        const main = () => {
            const
                win = document.windows[0],
                tasks = win.selection.tasks;
            return tasks.map(t => {
                const
                    alias = new Task(
                        t.name,
                        t.containingProject
                    );
                return (
                    alias.note = `omnifocus:///task/${t.id.primaryKey}`,
                    alias
                )
            })
        }
        return main();
    };


    // OmniJS Context Evaluation ------------------------------------------------
    return 0 < Application('OmniFocus').documents.length ? (
        Application('OmniFocus').evaluateJavascript(
            `(${omniJSContext})()`
        )
    ) : 'No documents open in OmniFocus.'
})();

Thanks! This didn’t work. :)

By which I mean I don’t know what I’m doing.

When I try to run or save it from script editor I get “Error on line 24: SyntaxError: Unexpected end of script”

Are you sure you did this step ?

And perhaps also worth checking a common problem:

are you sure that you have scrolled and copied all the way down to the bottom line ?

The pasted script should end with:


    // OmniJS Context Evaluation ------------------------------------------------
    return 0 < Application('OmniFocus').documents.length ? (
        Application('OmniFocus').evaluateJavascript(
            `(${omniJSContext})()`
        )
    ) : 'No documents open in OmniFocus.'
})();

Note the copy icon at top-right (when your cursor hovers over code in this forum) for that very reason:

Screenshot 2021-12-18 at 06.42.24

1 Like

An alternative workflow would be to apply a ‘Next Actions’ tag to the actions you’ve picked, go to that tag in the Tags perspective, and reorder the actions there. This keeps things dynamic if the picked actions change, such as being made unavailable or their attributes change.

That’s exactly what I did.

Thanks for being cool about it.

I always get confused about where I can reorder tasks manually. I always try to do in a perspective… Thanks for this idea.

1 Like

You can rearrange the order in perspectives in these 2 cases:

  • ‘Group and sort: Entire Projects’ (rearrange the order in the project)
  • The built-in Tags perspective, or ‘Individual Actions’, ‘Group actions by: Tag’, ‘Sort actions by: Tags Order’ (rearrange the custom order for a specific tag)

Any other type of perspective doesn’t display a set of actions for which OF tracks an order.