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.

Class Functions

Using the byIdentifier() method to locate a folder using the value of its primaryKey property (object ID):

Locating Folder by ID

Folder.byIdentifier('a0UDF6AROY8') //--> [object Folder: Home Renovation]

Using the flattenedFolders property of the Database class to return an object reference to the folder identified by name:

Locating 1st Instance of Folder by Name

var fldr = flattenedFolders.byName('Home Renovation') if(fldr){ console.log(fldr.id.primaryKey) //--> "a0UDF6AROY8" }

Instance Properties

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

Using the flattenedProjects property of the Folder class to iterate all projects within a specified folder:

Iterating All Projects in a Folder

var folderName = 'Home Renovation' var fldr = flattenedFolders.byName(folderName) if(fldr){ fldr.flattenedProjects.forEach(project => { // process project }) }

Folder.Status Class

The value for the status property of the Folder class:

Dropping a Folder

var folder = folderNamed("Folder A") if(folder){folder.status = Folder.Status.Dropped}

Creating Folders

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

Creating Folders within a Folder

var fldr = new Folder("AAPL", library.beginning) var titles = ["1st Q","2nd Q","3rd Q","4th Q"] titles.forEach(title => new Folder(title, fldr))
New Folder on iPad

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

Folder for Each Month

var locale = "en-us" var monthNames = [] for (i = 0; i < 12; i++) { var objDate = new Date() objDate.setDate(1) objDate.setMonth(i) monthName = objDate.toLocaleString(locale,{month:"long"}) monthNames.push(monthName) } var folderNames = folders.map(fldr => {return fldr.name}) monthNames.forEach((month)=>{ if(!folderNames.includes(month)){new Folder(month)} })

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:

Next Task for Specified Folder Project

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

Folder Hierarchy

Folders may contain projects and other folders. Contained folders may also contain folders and projects, and so on.

Here's a macOS-only function that will return the path string to the selected library item (folder or project), for example:

Top-Level Folder > Secondary-Level Folder > Third-Level Folder > Selected Project

Hierarchy Path for Selected Folder or Project

function pathToSelectedLibraryItem(){ if ( document.windows[0].perspective === Perspective.BuiltIn.Projects && document.windows[0].sidebar.selectedNodes.length === 1 ) { var item = document.windows[0].sidebar.selectedNodes[0].object var pathItems = [item.object.name] var lvl = item.level if(lvl > 1){ do { item = item.parent lvl = item.level pathItems.unshift(item.object.name) } while (lvl > 1) } var itemHeirarchy = pathItems.join(" > ") return itemHeirarchy } return null }