Folders

Folders provide a convenient mechanism for organizing your projects. Each folder may contain other folders and projects, and you copy and move their contents between folders.

Properties

Here are the properties of an instance of the Folder class:

Creating Folders

New folders are created using the standard Javascript new constructor, passing in values for the name and optinal insertion position parameters:

fldr = new Folder("AAPL", library.beginning) titles = ["1st Q","2nd Q","3rd Q","4th Q"] titles.forEach(title => new Folder(title, fldr))
omnifocus://localhost/omnijs-run?script=try%7Bfldr%20%3D%20new%20Folder%28%22AAPL%22%2C%20library%2Ebeginning%29%0Atitles%20%3D%20%5B%221st%20Q%22%2C%222nd%20Q%22%2C%223rd%20Q%22%2C%224th%20Q%22%5D%0Atitles%2EforEach%28title%20%3D%3E%20new%20Folder%28title%2C%20fldr%29%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
New Folder on iPad

An example script for creating a new top-level folder for each month of the year.

var locale = "en-us" var monthNames = [] for (i = 0; i < 12; i++) { var objDate = new Date() objDate.setMonth(i) monthName = objDate.toLocaleString(locale,{month:"long"}) monthNames.push(monthName) } folderNames = folders.map(fldr => {return fldr.name}) monthNames.forEach((month)=>{ if(!folderNames.includes(month)){new Folder(month)} })
omnifocus://localhost/omnijs-run?script=try%7BfolderNames%20%3D%20folders%2Emap%28fldr%20%3D%3E%20%7Breturn%20fldr%2Ename%7D%29%0Avar%20locale%20%3D%20%22en%2Dus%22%0Avar%20monthNames%20%3D%20%5B%5D%0Afor%20%28i%20%3D%200%3B%20i%20%3C%2012%3B%20i%2B%2B%29%20%7B%0A%09var%20objDate%20%3D%20new%20Date%28%29%0A%09objDate%2EsetMonth%28i%29%0A%09monthName%20%3D%20objDate%2EtoLocaleString%28locale%2C%7Bmonth%3A%22long%22%7D%29%0A%09monthNames%2Epush%28monthName%29%0A%7D%0AmonthNames%2EforEach%28%28month%29%3D%3E%7B%0A%09if%28%21folderNames%2Eincludes%28month%29%29%7Bnew%20Folder%28month%29%7D%0A%7D%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D

Folder Instance Functions

Here are the functions that can be applied to instances of the Folder class:

Here’s a script that processes the net task of a specified project located within a specified top-level directory:

project = folderNamed("Fall Festival").projectNamed("Setup To-Do List") if(project){ task = project.nextTask // processing statements }

A script using the apply(…) function to locate every folder in the library hierarchical chain:

var fldrs = new Array() library.apply(item => { if (item instanceof Folder){fldrs.push(item)} }) console.log(fldrs)
omnifocus://localhost/omnijs-run?script=try%7Bvar%20fldrs%20%3D%20new%20Array%28%29%20%0Alibrary%2Eapply%28item%20%3D%3E%20%7B%0A%09if%20%28item%20instanceof%20Folder%29%7Bfldrs%2Epush%28item%29%7D%20%0A%7D%29%0Aconsole%2Elog%28fldrs%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D

And here’s a script demonstrating how to locate the first folder with a specified name, in the entire Library hierarchy:

var targetFolderName = "Fall Festival" var targetFolder = null library.apply(function(folder){ // stop the iteration process when a match is found if (folder.name == targetFolderName ){ targetFolder = folder return ApplyResult.Stop } }) if(targetFolder){ console.log(targetFolder) // processing statements }
UNDER CONSTRUCTION

This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.

DISCLAIMER