×

Perspective

A Perspective is a view into your OmniFocus database that appears in the perspective list (left-side of window) and whose contents are detailed in the outline (right-side of window).

OmniFocus comes with built-in perspectives (Perspective.BuiltIn class): Flagged, Forecast, Inbox, Nearby, Projects, Review, and Tags; and two transient reference perspectives: Completed and Changed. Custom perspectives (Perspective.Custom class) can be created in OmniFocus Pro.

Perspective Properties

Here are the properties of both the built-in and custom perspective classes:

The Class Properties of the Perspective.BuiltIn class:

The Instance Properties of the Perspective.BuiltIn class:

The Instance Properties of the Perspective.Custom class:

An instance of either the built-in or custom Perspective class is the value of the perspective property of the Window class.

The Perspective Property of a Window


document.windows[0].perspective //--> [object Perspective.BuiltIn: Inbox]

Get the name of the current perspective:

Name of the Current Perspective


document.windows[0].perspective.name //--> "Projects"

Change window view to show Inbox perspective:

omnifocus://localhost/omnijs-run?script=try%7Bdocument%2Ewindows%5B0%5D%2Eperspective%20%3D%20Perspective%2EBuiltIn%2EInbox%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
Change Window to Inbox Perspective
 

document.windows[0].perspective = Perspective.BuiltIn.Inbox //--> [object Perspective.BuiltIn: Inbox]

Perspectives can also be shown using the OmniFocus URL schema:

omnifocus://localhost/omnijs-run?script=URL%2EfromString%28%22omnifocus%3A%2F%2F%2Fprojects%22%29%2Eopen%28%29
Show Projects Perspective
 

URL.fromString("omnifocus:///projects").open()

Custom Perspectives

Custom Perspectives are created by you to display items based upon the filtering parameters you define.

The properties of the Perspective.Custom class:

The Class Functions of the Perspective.Custom class:

The Instance Functions of the Perspective.Custom class:

Show a Custom Perspective


var p = Perspective.Custom.byName("Fairfield Project") if(p){document.windows[0].perspective = p}

Showing Custom Perspective using a URL

To display a custom perspective, you may optionally incorporate the built-in URL support of OmniFocus in the script:

Show Custom Perspective


var name = "Fairfield Project" var urlStr = "omnifocus:///perspective/" + encodeURIComponent(name) URL.fromString(urlStr).open()

(01) The name of the custom perspective to be shown.

(02) Append a percent-encoded verson of the custom perspective name to URL string targeting the current perspective in the OmniFocus application.

(03) Use the fromString(…) method of the URL class to convert the string into a URL object, and then execute the url by appending the open() function to the result.

Export the Chosen Custom Perspective

Here is an example plug-in that will display a menu of all available custom perspectives, and then the chosen perspective to file on disk.

Export Custom Perspective
 

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.export-custom-perspective", "version": "1.3", "description": "Exports the chosen custom perspective to file.", "label": "Export Custom Perspective", "shortLabel": "Export Perspective", "paletteLabel": "Export Perspective", "image": "rectangle.split.3x3" }*/ (() => { var action = new PlugIn.Action(async function(selection, sender){ try { perspectives = new Array() perspectives = perspectives.concat(Perspective.Custom.all) perspectiveNames = perspectives.map(perspective => { return perspective.name }) itemIndexes = new Array() perspectiveNames.forEach((name, index) => { itemIndexes.push(index) }) perspectiveMenu = new Form.Field.Option( "perspective", "Perspective", itemIndexes, perspectiveNames, 0 ) perspectiveMenu.allowsNull = false inputForm = new Form() inputForm.addField(perspectiveMenu) formPrompt = "Custom perspective to export:" buttonTitle = "Continue" formObject = await inputForm.show(formPrompt,buttonTitle) chosenPerspective = perspectives[formObject.values['perspective']] wrapper = chosenPerspective.fileWrapper() filesaver = new FileSaver() savedFileURL = await filesaver.show(wrapper) } catch(err){ if(!err.causedByUserCancelling){ new Alert(err.name, err.message).show() } } }); action.validate = function(selection, sender){ return (Perspective.Custom.all.length > 0) }; return action; })();

eMail the Chosen Custom Perspective (3.9)

Here is an example plug-in that will display a menu of all available custom perspectives, and then add the exported perspective file to a new outgoing email message.

eMail Custom Perspective
 

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.email-custom-perspective", "version": "1.0", "description": "Creates a new outgoing mail message with the chosen custom perspective.", "label": "eMail Custom Perspective", "shortLabel": "eMail Perspective", "paletteLabel": "eMail Perspective", }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code // selection options: tasks, projects, folders, tags var perspectives = new Array() perspectives = perspectives.concat(Perspective.Custom.all) var perspectiveNames = perspectives.map(perspective => { return perspective.name }) var itemIndexes = new Array() perspectiveNames.forEach((name, index) => { itemIndexes.push(index) }) var perspectiveMenu = new Form.Field.Option( "perspective", "Perspective", itemIndexes, perspectiveNames, 0 ) perspectiveMenu.allowsNull = false var inputForm = new Form() inputForm.addField(perspectiveMenu) var formPrompt = "Choose the custom perspective to export:" var buttonTitle = "Continue" var formPromise = inputForm.show(formPrompt,buttonTitle) formPromise.then(function(formObject){ var chosenPerspective = perspectives[formObject.values['perspective']] var pName = chosenPerspective.name var wrapper = chosenPerspective.fileWrapper() var email = new Email() email.subject = pName + " Perspective" email.body = "Here is a copy of my OmniFocus perspective: “" + pName + "”\n\n" email.fileWrappers = [wrapper] email.generate() }) formPromise.catch(function(err){ console.error("form cancelled", err.message) }) }); action.validate = function(selection, sender){ return (Perspective.Custom.all.length > 0) }; return action; })();

Add the Chosen Perspective

Here is the basic script for creating a new tab (macOS) or window (iPadOS) for a specified perspective:

New Tab/Window with Perspective


(async () => { var targetPerspective = Perspective.BuiltIn.Projects if (Device.current.mac){ var win = await document.newTabOnWindow(document.windows[0]) win.perspective = targetPerspective } else { var win = await document.newWindow() win.perspective = targetPerspective } })().catch(err => console.error(err.message))

And a version where the chosen perspective is added to a new tab or window:

omnifocus://localhost/omnijs-run?script=%28async%20%28%29%20%3D%3E%20%7B%0A%09%2F%2F%20remove%20Search%0A%09var%20bPerspectives%20%3D%20Perspective%2EBuiltIn%2Eall%0A%09idx%20%3D%20bPerspectives%2EindexOf%28Perspective%2EBuiltIn%2ESearch%29%0A%09if%20%28idx%20%3E%20%2D1%29%20%7B%0A%09%20%20bPerspectives%2Esplice%28idx%2C%201%29%3B%0A%09%7D%0A%09bPerspectives%2Esort%28%28a%2C%20b%29%20%3D%3E%20%7B%0A%09%20%20var%20x%20%3D%20a%2Ename%3B%0A%09%20%20var%20y%20%3D%20b%2Ename%3B%0A%09%20%20if%20%28x%20%3C%20y%29%20%7Breturn%20%2D1%3B%7D%0A%09%20%20if%20%28x%20%3E%20y%29%20%7Breturn%201%3B%7D%0A%09%20%20return%200%3B%0A%09%7D%29%0A%09bpNames%20%3D%20bPerspectives%2Emap%28p%20%3D%3E%20p%2Ename%29%0A%0A%09var%20cPerspectives%20%3D%20Perspective%2ECustom%2Eall%0A%09cPerspectives%2Esort%28%28a%2C%20b%29%20%3D%3E%20%7B%0A%09%20%20var%20x%20%3D%20a%2Ename%3B%0A%09%20%20var%20y%20%3D%20b%2Ename%3B%0A%09%20%20if%20%28x%20%3C%20y%29%20%7Breturn%20%2D1%3B%7D%0A%09%20%20if%20%28x%20%3E%20y%29%20%7Breturn%201%3B%7D%0A%09%20%20return%200%3B%0A%09%7D%29%0A%09var%20cpNames%20%3D%20cPerspectives%2Emap%28p%20%3D%3E%20p%2Ename%29%0A%09var%20pNames%20%3D%20bpNames%2Econcat%28cpNames%29%0A%09var%20itemIndexes%20%3D%20pNames%2Emap%28%28item%2C%20index%29%20%3D%3E%20index%29%0A%09var%20pObjs%20%3D%20bPerspectives%2Econcat%28cPerspectives%29%0A%0A%09var%20perspectivesMenu%20%3D%20new%20Form%2EField%2EOption%28%0A%09%09%22perspective%22%2C%20%0A%09%09%22Perspective%22%2C%20%0A%09%09itemIndexes%2C%20%0A%09%09pNames%2C%20%0A%09%090%0A%09%29%0A%0A%09var%20inputForm%20%3D%20new%20Form%28%29%0A%09inputForm%2EaddField%28perspectivesMenu%29%0A%09var%20formPrompt%20%3D%20%22Choose%20perspective%20to%20show%3A%22%0A%09var%20buttonTitle%20%3D%20%22Continue%22%0A%09var%20formObject%20%3D%20await%20inputForm%2Eshow%28formPrompt%2CbuttonTitle%29%0A%09var%20chosenIndex%20%3D%20formObject%2Evalues%5B%27perspective%27%5D%0A%09var%20chosenPerspective%20%3D%20pNames%5BchosenIndex%5D%0A%09var%20perspect%20%3D%20pObjs%5BchosenIndex%5D%0A%09%0A%09if%20%28Device%2Ecurrent%2Emac%29%7B%0A%09%09if%28perspect%20%3D%3D%3D%20Perspective%2EBuiltIn%2ENearby%29%7B%0A%09%09%20%09throw%20new%20Error%28%22Nearby%20not%20available%20on%20macOS%22%29%0A%09%09%7D%0A%09%09var%20win%20%3D%20await%20document%2EnewTabOnWindow%28document%2Ewindows%5B0%5D%29%0A%09%7D%20else%20%7B%0A%09%09var%20win%20%3D%20await%20document%2EnewWindow%28%29%0A%09%7D%0A%09win%2Eperspective%20%3D%20perspect%0A%7D%29%28%29%2Ecatch%28err%20%3D%3E%20new%20Alert%28err%2Ename%2C%20err%2Emessage%29%2Eshow%28%29%29
New View with Chosen Perspective
 

(async () => { // remove Search var bPerspectives = Perspective.BuiltIn.all idx = bPerspectives.indexOf(Perspective.BuiltIn.Search) if (idx > -1) { bPerspectives.splice(idx, 1); } bPerspectives.sort((a, b) => { var x = a.name; var y = b.name; if (x < y) {return -1;} if (x > y) {return 1;} return 0; }) bpNames = bPerspectives.map(p => p.name) var cPerspectives = Perspective.Custom.all cPerspectives.sort((a, b) => { var x = a.name; var y = b.name; if (x < y) {return -1;} if (x > y) {return 1;} return 0; }) var cpNames = cPerspectives.map(p => p.name) var pNames = bpNames.concat(cpNames) var itemIndexes = pNames.map((item, index) => index) var pObjs = bPerspectives.concat(cPerspectives) var perspectivesMenu = new Form.Field.Option( "perspective", "Perspective", itemIndexes, pNames, 0 ) var inputForm = new Form() inputForm.addField(perspectivesMenu) var formPrompt = "Choose perspective to show:" var buttonTitle = "Continue" var formObject = await inputForm.show(formPrompt,buttonTitle) var chosenIndex = formObject.values['perspective'] var chosenPerspective = pNames[chosenIndex] var perspect = pObjs[chosenIndex] if (Device.current.mac){ if(perspect === Perspective.BuiltIn.Nearby){ throw new Error("Nearby not available on macOS") } var win = await document.newTabOnWindow(document.windows[0]) } else { var win = await document.newWindow() } win.perspective = perspect })().catch(err => new Alert(err.name, err.message).show())

Here is an example plug-in that will display a menu of all available perspectives, and then open the chosen perspective in a new tab (macOS) or a new window (iOS and iPadOS).

Screenshot

(⬆ see above ) The Add Chosen Perspective plug-in has no contextual selection requirements so it is available in the Share menu when no elements are selected in the app interface.

Add the Chosen Perspective
 

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.add-chosen-perspective", "version": "1.2", "description": "This action will add a new tab (macOS) or window (iPadOS) displaying the chosen perspective.", "label": "Add Chosen Perspective", "shortLabel": "Add Chosen Perspective", "paletteLabel": "Add Chosen Perspective", "image": "uiwindow.split.2x1" }*/ (() => { const action = new PlugIn.Action(async function(selection, sender){ try { perspectives = new Array() perspectives = perspectives.concat(Perspective.BuiltIn.all) perspectives = perspectives.concat(Perspective.Custom.all) perspectiveNames = perspectives.map(perspective => perspective.name) itemIndexes = new Array() perspectiveNames.forEach((name, index) => { itemIndexes.push(index) }) perspectiveMenu = new Form.Field.Option( "perspective", "Perspective", itemIndexes, perspectiveNames, 0 ) perspectiveMenu.allowsNull = false inputForm = new Form() inputForm.addField(perspectiveMenu) formPrompt = "Choose the perspective:" buttonTitle = "Continue" formObject = await inputForm.show(formPrompt, buttonTitle) chosenIndex = formObject.values['perspective'] chosenPerspective = perspectives[chosenIndex] if (Device.current.mac){ win = await document.newTabOnWindow(document.windows[0]) } else { win = await document.newWindow() } win.perspective = chosenPerspective } catch(err){ if(!err.causedByUserCancelling){ new Alert(err.name, err.message).show() } } }); action.validate = function(selection, sender){ return true }; return action; })();

Adjusting Filter Rules using Omni Automation

Beginning with OmniFocus v4.2 the Perspective.Custom class now has two new instance properties that provide access to the filter rules of custom perspectives:

Using these new properties, you can both access and alter the filtering rules for a custom perspective using Omni Automation:

Getting Rules for Current Custom Perspective


document.windows[0].perspective.archivedTopLevelFilterAggregation //--> "all" document.windows[0].perspective.archivedFilterRules //--> [{actionAvailability: "available"}, {actionHasAnyOfTags: ["ni5R6QIk4aO"]}]

Version of the previous script that uses the JSON.stringify() function to display the results in the console as formatted JSON:

Getting Rules for Current Custom Perspective


document.windows[0].perspective.archivedTopLevelFilterAggregation //--> "all" rulesArchive = document.windows[0].perspective.archivedFilterRules console.log(JSON.stringify(rulesArchive, undefined, 2)) /* [ { "actionAvailability": "available" }, { "actionHasAnyOfTags": [ "ni5R6QIk4aO" ] } ] */
An example of Filter Rules

The following script alters the value of the actionAvailability filter while retaining the value of the actionHasAnyOfTags filter:

Changing Rules for Current Custom Perspective


tagID = flattenedTags.byName("Special").id.primaryKey currentPerspective = document.windows[0].perspective currentPerspective.archivedFilterRules = [{actionAvailability: "remaining"}, {actionHasAnyOfTags: [tagID]}]
Altered filter rules for current perspective

The following script demonstrates a function that changes just the value of a specific rule in the currently displayed custom perspective:

Changing Value of a Specified Rule


function changeValueForRule(ruleName, ruleValue){ cp = document.windows[0].perspective rulesObjArray = cp.archivedFilterRules for (rulesObj of rulesObjArray){ if (rulesObj.hasOwnProperty(ruleName)){ rulesObj[ruleName] = ruleValue break } } cp.archivedFilterRules = rulesObjArray } // Pass the rule and new value to function changeValueForRule("actionAvailability", "available")

This variation of the previous function will either change the value of the specified rule if the rule exists in the archive, or add the rule with the indicated value if the rule does not currently exist in the archive.

Set Value of a Specified Rule


function setValueForRule(ruleName, ruleValue){ cp = document.windows[0].perspective rulesObjArray = cp.archivedFilterRules didChange = false for (rulesObj of rulesObjArray){ if (rulesObj.hasOwnProperty(ruleName)){ rulesObj[ruleName] = ruleValue didChange = true console.log("Changing value…") break } } if(!didChange){ console.log("Added rule…") obj = new Object() obj[ruleName] = ruleValue rulesObjArray.push(obj) } console.log(JSON.stringify(rulesObjArray, undefined, 2)) cp.archivedFilterRules = rulesObjArray } // Pass the rule and new value to function setValueForRule("actionHasNoProject", true)

Filter Rules and Values

Here are the variations of possible filter rules and their values:

Filter Rules and Values


archivedTopLevelFilterAggregation: "any", "all", "none" /* AVAILABILITY */ { actionAvailability: "firstAvailable" /* "available", "remaining", "completed", "dropped" */ } /* STATUS */ { actionStatus: "due" /* "flagged" */ } /* HAS A DUE DATE */ { actionHasDueDate: true } /* HAS A DEFER DATE */ { actionHasDeferDate: true } /* AN ESTIMATED DURATION */ { actionHasDuration: true } /* AN ESTIMATED DURATION LESS THAN */ { actionWithinDuration: 5 /* 15, 30, 60 */ } /* ITEM IS A PROJECT */ { actionIsProject: true } /* ITEM IS A GROUP */ { actionIsGroup: true } /* ITEM IS A PROJECT OR GROUP */ { actionIsProjectOrGroup: true } /* ITEM REPEATS */ { actionRepeats: true } /* DATE FIELD */ { actionDateField: "due", /* "defer", "completed", "dropped", "added", "changed" */ /* USE ONE DATE INDICATOR */ /* ON */ actionDateIsOnDateSpec: { dynamic: "TEXT" } /* YESTERDAY */ actionDateIsYesterday: true /* TODAY */ actionDateIsToday: true /* TOMORROW */ actionDateIsTomorrow: true /* IN THE PAST */ actionDateIsInThePast: { relativeBeforeAmount: 000, relativeComponent: "year" /* "month", "week", "day", "hour" */ } /* IN THE NEXT */ actionDateIsInTheNext: { relativeAfterAmount: 000, relativeComponent: "year" /* "month", "week", "day", "hour" */ } /* BETWEEN */ actionDateIsAfterDateSpec: { dynamic: "TEXT" }, actionDateIsBeforeDateSpec: { dynamic: "TEXT" } } } /* IS UNTAGGED */ { actionIsUntagged: true } /* HAS TAG THAT… */ { actionHasTagWithStatus: "remaining" /* "onHold", "dropped", "active", "stalled" } /* TAGGED WITH ANY OF… */ { actionHasAnyOfTags: ["TAG-ID", "TAG-ID", "…"] } /* TAGGED WITH ALL OF… */ { actionHasAllOfTags: ["TAG-ID", "TAG-ID", "…"] } /* IS NOT PROJECT OR GROUP */ { actionIsLeaf: true } /* IS IN THE INBOX */ { actionHasNoProject: true } /* IS IN SINGLE ACTIONS LIST */ { actionIsInSingleActionsList: true } /* HAS A PROJECT THAT… */ { actionHasProjectWithStatus: "active" /* "remaining", "onHold", "completed", "dropped", "stalled", "pending" */ } /* CONTAINED WITHIN PROJECT OR FOLDER… */ { actionWithinFocus: ["OBJ-ID", "OBJ-ID", "…"] } /* MATCHES SEARCH TERMS */ { actionMatchingSearch: ["PHRASE ONE", "PHRASE TWO", "…"] } /* AGGREGATE TYPE */ { aggregateType: "any" /* "all", "none" */ }