×

Projects

A Project is a container for organizing and managing the tasks related to a specific topic or event. Projects are usually comprised of tasks that are designed to be processed in sequence, together, or in an order chosen by the user. Projects share many of the same properties and functions with tasks.

In this section of the tutorial, you’ll learn how to create projects, set the value of their properties, and populate them with tasks.

To begin, let’s examine where projects are surfaced in the OmniFocus interface.

DO THIS ►

The Projects Perspective displays a list of your projects in the sidebar. Run the following script that sets the value of the perspective property of the Window class so that the Projects Perspective is displayed:

document.windows[0].perspective = Perspective.BuiltIn.Projects
omnifocus://localhost/omnijs-run?script=try%7Bdocument%2Ewindows%5B0%5D%2Eperspective%20%3D%20Perspective%2EBuiltIn%2EProjects%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
Show the Projects Perspective
 

document.windows[0].perspective = Perspective.BuiltIn.Projects

The Projects Perspective will now be displayed in OmniFocus. TIP: you can use this script to change the currently displayed perspective by replacing the Projects property of the Perspective.BuiltIn class to: Flagged, Forecast, Inbox, Nearby, Tags, Search, or Review

New Project

Instances of the Project class are created using the standard JavaScript new item constructor, with the name of the new project as the parameter passed into the function:

As with tags and tasks, there is no limitation as to the naming of projects. You can have multiple projects titled using the same name. If maintaining an OmniFocus database of unique project names is important to you, the same functions we used in the previous section to ensure unique tags can be adapted for use with the creation and referencing of projects:

var projName = "4-Step Success" var projObj = flattenedProjects.byName(projName) || new Project(projName)
omnifocus://localhost/omnijs-run?script=try%7Bvar%20projName%20%3D%20%224%2DStep%20Success%22%0Avar%20projObj%20%3D%20flattenedProjects%2EbyName%28projName%29%20%7C%7C%20new%20Project%28projName%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
Unique Top-Level Project


var projName = "4-Step Success" var projObj = flattenedProjects.byName(projName) || new Project(projName)

For the purposes of this tutorial, we’ll use the basic project new item constructor to create a new instance of the Project class at the top-level of the projects list.

DO THIS ►

Enter and run the following script:

omnifocus://localhost/omnijs-run?script=try%7Bvar%20projName%20%3D%20%224%2DStep%20Success%22%0Avar%20projObj%20%3D%20new%20Project%28projName%2C%20library%2Ebeginning%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
New Project
 

var projName = "4-Step Success" var projObj = new Project(projName, library.beginning)

A new project is created and the object reference to it has been stored in the variable: projObj

NOTE: The property library of the Database class (line 2 in the previous script) represents the top-level folders and projects in the database, which are displayed in the Projects Perspective. This property also supports the use of the apply(…) method to iterate library content.

new-project

Now that the project has been created, it can be populated with actions, beginning with the first three actions in the Inbox.

NOTE: the value of the inbox property of the Database class is an array of object references to the tasks in the Inbox. We can create an array of object references to the first three tasks in the Inbox by using the JavaScript splice(…) function.

1st Three Inbox Tasks


var taskObjs = inbox.splice(0,3) //--> [[object Task: TASK ONE], [object Task: TASK TWO], [object Task: TASK THREE]]

 1  The first parameter of the splice(…) function is the index of the item to begin the spliced array. Second parameter is how many items to include in the spliced array. The resulting array of references is stored in the variable: taskObjs

 2  The result is an array of three object references to the first three tasks in the Inbox.

Now that we have identified the previously created tasks, we can use the moveTasks(…) function of the Database class to move the identified tasks into the newly created project.

DO THIS ►

Enter and run the following script for moving the inbox tasks into the newly created project:

var taskObjs = inbox.splice(0,3) moveTasks(taskObjs, projectNamed("4-Step Success").beginning)
omnifocus://localhost/omnijs-run?script=try%7Bvar%20taskObjs%20%3D%20inbox%2Esplice%280%2C3%29%0AmoveTasks%28taskObjs%2C%20projectNamed%28%224%2DStep%20Success%22%29%2Ebeginning%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
Move Tasks into Project
 

var taskObjs = inbox.splice(0,3) moveTasks(taskObjs, projectNamed("4-Step Success").beginning)

The previously created project will now contain the three tasks moved from the Inbox:

tasks-moved-into-project

Since the title of the targeted project is “4-Step Success” and it contains three tasks, we need to create one more task. Let’s add another task to the project.

DO THIS ►

Enter and run the following script:

new Task("Task Four", projectNamed("4-Step Success").ending)
omnifocus://localhost/omnijs-run?script=try%7Bnew%20Task%28%22Task%20Four%22%2C%20projectNamed%28%224%2DStep%20Success%22%29%2Eending%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
Add 4th Task to Project
 

new Task("Task Four", projectNamed("4-Step Success").ending)

A fourth task is added to the end of project tasks:

4th-task-in-project

Project Properties

With all four tasks now in place in the project, we can change the value of a couple of project properties to alter the way the project functions.

For this example, we want the project tasks to be completed in order, and when the last task of the project is completed, the project is to be marked as completed. We can change the default values of the following properties of the example project to accomplish our goals:

DO THIS ►

Enter and run the following script:

var projObj = projectNamed("4-Step Success") projObj.sequential = true projObj.completedByChildren = true
omnifocus://localhost/omnijs-run?script=try%7Bvar%20projObj%20%3D%20projectNamed%28%224%2DStep%20Success%22%29%0AprojObj%2Esequential%20%3D%20true%0AprojObj%2EcompletedByChildren%20%3D%20true%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
Set Project Properties
 

var projObj = projectNamed("4-Step Success") projObj.sequential = true projObj.completedByChildren = true

The example project will now be display a sequential project icon (see arrow below), and the first task is enabled while the others are disabled:

project-properties

To edit the properties of an existing project task, append the taskNamed(…) function to an object reference to the parent project:

DO THIS ►

Enter and run the following script:

projectNamed("4-Step Success").taskNamed("Task One").flagged = true
omnifocus://localhost/omnijs-run?script=try%7BprojectNamed%28%224%2DStep%20Success%22%29%2EtaskNamed%28%22Task%20One%22%29%2Eflagged%20%3D%20true%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
Edit Task in Project
 

projectNamed("4-Step Success").taskNamed("Task One").flagged = true

The first task in the sequence of project tasks will be flagged:

project-task-edited

Summary

In this section you learned:

In the next section, you will learn how to create and install plug-ins.