Drafts Scripting Reference

Things

Things is a popular task and project management app from Cultured Code. Things supports advanced URL schemes (required Things v3.4 or greater on iOS) which can accept multiple todos, projects, headings in a single call to the app. The scripting interfaces below are convenience wrappers that allow easy creation and encoding of the URLs needed to pass this type of information to Things.

The Javascript objects are wrappers around an open source Swift library provided by Cultured Code, with a few modifications to work in Javascript. In all cases, nothing is committed to Things until the the items are wrapped in a TJSContainer, and the URL it generates called to send the data to Things. This is best done with Drafts’ CallbackURL object (see example below).

For more information about what values Things understands in these objects, refer to their URL scheme documenation.

Objects

TJSContainer

Wraps an array of todo and/or project items and encodes them into a URL for use to send the request to Things.

TJSProject

Represents a Things project, with headings and todo items.

TJSHeading

Represents a Things heading within a project.

TJSTodo

Represents a Things todo item. Todos can be added a project or directly to a container.

TJSChecklistItem

Represents a Things check list item, which can be added to a Todo.

Examples

// create a Things Project
var project = TJSProject.create();
project.title = "My Project From Drafts";
project.notes = "Let's do this stuff";

// create and add a heading to the project
var heading = TJSHeading.create();
heading.title = "First Heading";
project.addHeading(heading);

// add todos to the project
var todo1 = TJSTodo.create();
todo1.title = "My first todo";
todo1.when = "today";
project.addTodo(todo1);

var todo2 = TJSTodo.create();
todo2.title = "My second todo";
todo2.when = "tomorrow";
project.addTodo(todo2);

// create a container to handle creation of Things URL
var container = TJSContainer.create([project]);

// Use CallbackURL object to open URL in Things.
var cb = CallbackURL.create();
cb.baseURL = container.url;
var success = cb.open();
if (success) {
	console.log("Project created in Things");
}
else {
	context.fail();
}