Scripts

A script is a short TypeScript program that works over a copy of your tasks, notes and events. It can't change anything by itself. It proposes changes, such as a new note or a completed task, and you choose which ones to apply. A script can't reach the internet or the files on your computer.

Make a script

On Desk, choose New, then Script. The editor suggests names as you type. Format tidies the code, and the book button opens the script guide, which lists everything a script can use.

Run it

  • Run, or Cmd+Enter (Ctrl+Enter on Windows and Linux), runs the script and shows the changes it proposes. Each one has a checkbox, and all are ticked to start. Untick any you don't want, then choose Apply. Nothing changes before that.
  • Preview runs it the same way, with no way to apply anything.

What a script can read

NameWhat it holds
bb.tasksYour tasks: title, whether it's done, priority from 1 to 4, due date
bb.notesYour notes: title, text, tags
bb.eventsYour calendar events: title, start, end, all day, location, description
bb.today, bb.nowThe date and time the run started

bb.datetime adds minutes, hours, days or weeks to a date and formats dates the same way on every device.

What a script can propose

CallProposes
bb.createFile(title, content, format?)A new note. The format can also be docs, sheet or page
bb.createTask(title, priority?)A new task
bb.completeTask(id)Completing one of your tasks
bb.createEvent(title, start, end, options?)A calendar event

An example

This script proposes one note that lists your overdue tasks:

const overdue = bb.tasks.filter(
  (task) => !task.completed && task.due_date && bb.datetime.date(task.due_date) < bb.today,
);
if (overdue.length > 0) {
  bb.createFile('Overdue', overdue.map((task) => '- [ ] ' + task.title).join('
'));
}

Asking blackbear a question

bb.decide lets a script ask Blackbear Cloud a yes-or-no question, a choice between options or a score, and use the answer. Turn on Decisions in Settings, under Pax, first. Each call is paid, so ask related questions in one call.

Other ways to run a script

  • A Run Script block puts a button for it on one of your pages.
  • Pax can run your scripts too, and asks you before it does.