Bläck StudioPlugin SDK v1.0.0 · API 10
Contents

Start

Building

Beyond Bläck Studio

How it runs

Sharing

Look up

Write plugins for Bläck Studio

Bläck Studio is a writing app for long-form fiction. Plugins add to it: commands and hotkeys, views and inspector tabs, cards on the dashboard, marks in the text, formats in Compile, importers, suggestions as you type, and more. They're written in TypeScript or plain JavaScript, against @black-studio/plugin.

npm create @black-studio/plugin my-plugin
cd my-plugin
npm install
npm run dev      # builds into Bläck Studio’s plugins folder on every save

A plugin is a folder with a manifest.json and a script. Bläck Studio finds plugins in its plugins folder:

SystemFolder
Linux~/.local/share/black-studio/plugins/ (or $XDG_DATA_HOME/black-studio/plugins)
macOS~/Library/Application Support/black-studio/plugins/
Windows%APPDATA%\black-studio\plugins\

Settings → Plugins opens this folder and turns plugins on and off.

Starting one

The SDK is the npm package @black-studio/plugin. Start a plugin with:

npm create @black-studio/plugin my-plugin             # in the window, with React
npm create @black-studio/plugin my-plugin --sandboxed
npm create @black-studio/plugin my-plugin --computer  # sandboxed, with files and a program
cd my-plugin
npm install
npm run dev

There are three starting points:

  • In the window: a command with a hotkey, and an inspector tab drawn with React.
  • --sandboxed: a command, marks in the text, and text in the status bar, all running in a separate worker.
  • --computer: a sandboxed plugin with files:write and exec:pandoc. It saves the scene the writer is in as a Word file. Pandoc makes the file in the plugin's temporary folder, and the plugin then saves it in a folder the writer chooses. It remembers that folder for next time. The template shows how to ask for a folder, run a program, and tell the writer plainly when the program isn't installed. To run another program, name it in the manifest and in the code.

npm run dev builds the plugin into the plugins folder every time you save, and Bläck Studio reloads it as soon as it lands. Turn it on once under Settings → Plugins. npm run build makes dist/<id>/ to share, and a zip with its SHA-256 for the plugin list.

A plugin in plain JavaScript needs no build at all. A main.js like this, next to the manifest, is a complete plugin. A plain script asks for the SDK by its older name, @black/plugin, which every version of Bläck Studio knows. The build does the same for you.

var __blackPlugin = class extends __black.require('@black/plugin').Plugin {
  onload() {
    this.addCommand({ id: 'hello', name: 'Say hello', run: () => this.app.ui.notify('Hello') })
  }
}