API reference
Everything a plugin is written against, from the SDK’s index.d.ts. A plugin is a class that extends Plugin; it reaches the rest of Bläck Studio through this.app.
@black-studio/plugin: the API that Bläck Studio plugins are written against.
import { Plugin } from '@black-studio/plugin'
export default class WordOfTheDay extends Plugin { onload() { this.addCommand({ id: 'hello', name: 'Say hello', run: () => this.app.ui.notify('Hello') }) } }
A plugin runs in one of two places:
- In the app's window, where it can draw its own interface with React. It shares the app's copy of React: import React from 'react'.
- In a separate worker, if its manifest has "sandboxed": true. It can use everything here except what draws its own interface (views, inspector tabs, sidebar panels, dashboard cards, settings panels, its own dialogs and editor extensions), editor.active, editor.anchor and app.speech.
Code that avoids those features works in both places.
Everything a plugin adds through these methods is removed when the plugin is turned off or reloaded. A plugin can access the book only through this.app, and the internet only through this.app.net, limited to the hosts its manifest names (or addresses the writer entered) and the writer allowed.
Plugin class
readonly app: Appreadonly manifest: Manifestsettings: Record<string, unknown>The current values of the settings declared with addSettings.
onload(): void | Promise<void>Called when the plugin starts. Add commands, views and so on here.
onunload(): voidCalled when the plugin is turned off. Clean up anything the app doesn't remove itself.
Every add… method returns a function that removes what it added (the text form of addStatusBarItem returns an object instead), which is useful when a setting changes what a plugin offers. Anything still there is removed when the plugin is turned off.
register(dispose: () => void): voidRegisters something to clean up when the plugin is turned off, such as a timer or a listener.
addCommand(command: {
id: string
name: string
hotkey?: string
menu?: boolean
when?: () => boolean
run: () => void | Promise<void>
}): () => voidAdds a command to the command palette (Ctrl+K) and, unless menu is false, the Plugins menu. hotkey looks like "Mod+Shift+F", where Mod is Ctrl or ⌘.
addView(view: { id: string; name: string; icon?: ComponentType<{ size?: number }>; render: () => ReactNode }): () => voidAdds a view beside the corkboard and outliner. Window only.
addInspectorTab(tab: {
id: string
name: string | ((nodeId: string) => string)
when?: (nodeId: string, node: { type: NodeType; title: string }) => boolean
render: (nodeId: string) => ReactNode
}): () => voidAdds a tab to the inspector, for items where when returns true. Window only.
addStatusBarItem(item: { id: string; render: () => ReactNode }): () => voidAdds a status bar item. Either draw it with render (window only), or give it text and change that with setText, which also works in a sandboxed plugin.
addStatusBarItem(item: { id: string; text: string; title?: string; onClick?: () => unknown }): {
setText(text: string, title?: string): void
}addEditorMenuItem(item: {
id: string
label: string | ((ctx: EditorContext) => string)
show?: 'selection' | 'no-selection' | 'always'
when?: (ctx: EditorContext) => boolean
run: (ctx: EditorContext) => void | Promise<void>
}): () => voidAdds an item to the editor's right-click menu. show defaults to 'always'. In a sandboxed plugin, the label must be a string and when isn't available, so use show.
addBinderMenuItem(item: {
id: string
label: string | ((nodeId: string) => string)
when?: (nodeId: string) => boolean
run: (nodeId: string) => void | Promise<void>
}): () => voidAdds an item to the navigator's right-click menu.
addExporter(exporter: {
id: string
name: string
description?: string
extension: string
export: (book: ExportInput) => string | Uint8Array | Promise<string | Uint8Array>
}): () => voidAdds a format to Compile. Return text, or bytes for a binary format.
addHighlighter(highlighter: {
id: string
color?: string
find: (text: string) => HighlightRange[] | Promise<HighlightRange[]>
/** Called when the writer chooses one of a mark's `actions` from its right-click menu. API 6. */
onAction?: (action: string, mark: MarkInfo) => unknown
}): () => voidAdds marks to the text, found one paragraph at a time. The app draws them, and they're never saved.
refreshHighlights(): voidRuns every highlighter again, for example after a setting that affects them changes.
registerEditorExtension(extension: AnyExtension | AnyExtension[]): () => voidAdds TipTap extensions to every editor. Window only.
addSidebarPanel(panel: { id: string; name: string; render: () => ReactNode }): () => voidAdds a panel to the sidebar, beside the binder. Window only.
addToolbarButton(button: {
id: string
title: string
icon?: ComponentType<{ size?: number }> | string
active?: () => boolean
run: () => void | Promise<void>
}): () => voidAdds a button to the editor's toolbar. In a sandboxed plugin, the icon is text, such as an emoji.
addSuggester(suggester: {
id: string
trigger: string
find: (query: string, ctx: { docId: string }) => Suggestion[] | Promise<Suggestion[]>
}): () => voidShows suggestions under the caret as the writer types after trigger ("@", "#"…) at the start of a word. trigger must be a single character.
addImporter(importer: {
id: string
name: string
extensions: string[]
import: (file: ImportFile) => { title: string; html: string }[] | Promise<{ title: string; html: string }[]>
}): () => voidAdds a file type the app can't read itself to File → Import Documents. Each file becomes one or more documents.
addBookImporter(importer: {
id: string
/** The name in File → Import: "Scrivener Project". */
name: string
/** The app name for "Import from …" on the welcome screen: "Scrivener". Defaults to `name`. */
from?: string
/** The file extensions without the dot: ["pltr"]. For a folder, use the folder's extension: ["scriv"]. */
extensions: string[]
/** True if it reads a folder (a .scriv), not a file. Phones can't choose folders, so the writer chooses a zip of it. */
folder?: boolean
import: (source: ImportSource) => ImportedBook | Promise<ImportedBook>
}): () => voidImports a whole book from another app's file or folder, such as a Scrivener project or a Plottr outline. It appears in File → Import, and on the welcome screen while the plugin is on.
The app asks for the file or folder, passes it to import, and shows the writer the result. The writer can then make it a new book or add it to the open one. To explain why a file can't be read, throw an Error: the writer sees its message. This needs no permission, because it reads only what the writer picked. API 7.
addDashboardWidget(widget: {
id: string
name: string
size?: 'half' | 'full'
order?: number
render: () => ReactNode
}): () => voidAdds a card to the welcome screen's dashboard, shown while no book is open. size is 'half' (the default) or 'full' width. Cards are sorted by order, lowest first (default 100). These only set where a card starts: the writer can move it and change its width later. Window only. API 2.
addSettings(fields: SettingField[]): () => voidAdds settings that the app draws in Settings → Plugins. Read their values from this.settings.
addSettingsPanel(render: () => ReactNode): () => voidAdds a settings panel that the plugin draws itself. Window only.
onSettingsChange(listener: (settings: Record<string, unknown>) => void): voidupdateSettings(patch: Record<string, unknown>): Promise<void>on(event: PluginEvent, handler: (arg: string | null) => void): voidduring(event: 'session-end' | 'copy-due' | 'project-closing', handler: (info: WaitInfo) => unknown): () => voidRegisters a handler for a moment when the app waits for plugins:
- 'session-end': a writing session ended, after 30 minutes without writing or because the book is closing.
- 'copy-due': the writing timer is due and something has changed, or a new book was created.
- 'project-closing': a book is closing, or the app is quitting.
If the handler returns a promise, the app waits for it for up to 30 seconds (10 for 'session-end'), then carries on. A plugin has one handler per event: calling during again for the same event replaces it. API 10.
addVersionHistory(history: {
id: string
list(file?: string): Promise<VersionEntry[]>
read(version: string, file: string): Promise<string>
save(message: string): Promise<boolean>
status?(): Promise<{ text: string; problem?: boolean } | null>
}): () => voidProvides a version history of the project, which the app shows in Book → Versions & Backups and in a document's history. The app does the drawing, so this works in a sandboxed plugin. The plugin implements:
list: the versions, newest first. Withfile(a path in the project's folder), only those that changed it.read: a file's text in a version.save: saves a version with the writer's message. Returns false if nothing has changed since the last one.status(optional): a message for the writer, such as a failed backup, or null.
The app handles restoring, and always takes a snapshot of the document first. If more than one plugin provides a history, the app shows the first. API 10.
versionsChanged(): voidTells the app that the list of versions changed, so it reloads what it shows. API 10.
loadData(): Promise<unknown>The plugin's own data on this computer. For data stored in the book, see app.project.getData.
saveData(data: unknown): Promise<void>App interface
readonly apiVersion: numberreadonly language: stringThe language of the app's interface: 'en', 'sv'…
app.project
The open book. Changing it needs "project:write". Every change can be undone, and the app takes a snapshot of a document before a plugin first rewrites it.
isOpen(): Promise<boolean>info(): Promise<{ title: string; author: string; language: string; series: string | null } | null>nodes(): Promise<NodeInfo[]>node(id: string): Promise<NodeInfo | null>manuscript(): Promise<string[]>The manuscript's documents, in reading order.
selected(): Promise<string | null>select(id: string): Promise<void>read(id: string): Promise<string>A document's text as HTML.
readText(id: string): Promise<string>A document's text as plain text.
write(id: string, html: string): Promise<void>create(type: 'text' | 'folder' | 'character' | 'place' | 'note' | 'research', title: string, parentId?: string): Promise<string>meta(id: string): Promise<MetaInfo | null>setMeta(id: string, patch: Partial<Pick<MetaInfo, 'synopsis' | 'notes' | 'keywords' | 'fields' | 'when'>>): Promise<void>trash(id: string): Promise<void>Moves an item to the trash, where the writer can restore it.
rename(id: string, title: string): Promise<void>move(id: string, parentId: string, index?: number): Promise<void>Moves an item into a folder, at index among its children, or at the end if there's no index.
labels(): Promise<Label[]>statuses(): Promise<Status[]>setLabel(id: string, labelId: string): Promise<void>Sets an item's label by the label's id, or '' to clear it. setStatus works the same way.
setStatus(id: string, statusId: string): Promise<void>comments(id: string): Promise<{ id: string; text: string; created: string; resolved: boolean }[]>resolveComment(id: string, commentId: string, resolved?: boolean): Promise<void>snapshots(id: string): Promise<{ label: string; taken: string; html: string }[]>snapshot(id: string, label: string): Promise<void>Saves a snapshot of a document as it is now. This needs no permission.
search(
query: string,
opts?: { wholeWord?: boolean; caseSensitive?: boolean; regex?: boolean },
): Promise<{ id: string; title: string; line: number; excerpt: string }[]>Searches the book, like Find in Project.
series(): Promise<{ name: string; books: { id: string; title: string; current: boolean }[] } | null>The book's series and its books in order, or null if the book isn't in a series.
flush?(): Promise<void>Resolves once every pending change is saved to disk. API 10: check that it exists.
getProjectData?(): Promise<unknown>This plugin's data for the whole project, or undefined. It's stored in the project's project.json on this device, and isn't shared on Bläck Sync. If the project.json can't be read, getProjectData returns undefined and setProjectData throws. API 10: check that it exists.
setProjectData?(value: unknown): Promise<void>open?(key: string): Promise<boolean>Opens a project that this plugin created with folder.create, by its key. Returns false if it couldn't be opened. API 10: check that it exists.
getData(): Promise<unknown>This plugin's data for this book, saved in the book.
setData(value: unknown): Promise<void>app.editor
active(): Editor | nullThe TipTap editor the writer is using. Window only: it's null in a sandboxed plugin.
selection(): Promise<{ text: string; from: number; to: number } | null>insertText(text: string): Promise<boolean>Types text at the caret, replacing any selection. Returns false if no editor is active. Needs "project:write".
comment(text: string): Promise<boolean>Adds a margin comment on the selection. Returns false if nothing is selected. Needs "project:write".
anchor(): Promise<EditorAnchor | null>Returns a position for inserting text as it arrives, as dictation does: the writer's cursor, or where it was before they clicked a button, or else the end of the open document. The position moves with edits around it. Returns null if no document is open. Needs "project:write". Window only. API 4.
app.ui
notify(message: string, action?: { label: string; run: () => void }): voidShows a notice, with a button if you pass an action. A sandboxed plugin's notice has no button.
confirm(title: string, detail?: string, confirmLabel?: string): Promise<boolean>Asks a yes-or-no question in an app dialog. confirmLabel defaults to "OK". Resolves to true if the writer confirms.
openView(viewId: string): voidShows one of this plugin's views. Window only.
openSettings(): voidShows this plugin's settings.
openModal(modal: {
title: string
render: (close: () => void) => ReactNode
wide?: boolean
/** Called when the dialog closes: 'closed' if the writer closed it (Escape, ✕) or `close` was called, 'replaced' if another dialog took its place. */
onClose?: (how: 'closed' | 'replaced') => void
}): () => voidOpens a dialog that the plugin draws itself. Returns a function that closes it. Window only.
prompt(opts: { title: string; label?: string; value?: string; placeholder?: string }): Promise<string | null>Asks for a line of text. Returns null if the writer cancels.
choose(opts: { title: string; options: { value: string; label: string; detail?: string }[] }): Promise<string | null>Asks the writer to choose one option. Returns null if they cancel.
startSprint(minutes: number): voidStarts a writing sprint of 1 to 600 minutes in the open book, like the status bar's sprint. Throws if no book is open. API 2.
listMarks?(opts: {
highlighter: string
title: string
/** The heading for quiet marks (HighlightRange.quiet), which are listed last, each with its actions. API 9. */
quietTitle?: string
}): Promise<boolean>Shows a list of the marks from one of this plugin's highlighters in the current document, each with its surrounding text. The app selects the mark the writer picks. Resolves to false if there are no marks or the writer picks none. API 6: check that it exists before calling it.
app.folder
The open project's folder, which holds its books. Needs "project:folder". API 10: check that it exists before using it.
Paths are relative to the project's folder and use "/" as the separator. A path is refused if it's absolute, contains "..", goes through a symbolic link, has a name that isn't valid on every system, or names .sync (at any level) or .git (below the top level). Every call takes the project's key from current() instead of a path, so work started on one project can't end up in the next one opened. A key stops working two minutes after its project closes.
current(): Promise<ProjectFolder | null>Returns the open project's key, name and book folder (books/<id>), or null if no project is open.
create(title: string, name: string): Promise<ProjectFolder | null>Asks the writer where to create a new project and creates its folder, for a plugin that brings in a project from elsewhere. title is the dialog's title and name the suggested folder name. Returns null if the writer cancels.
discard(key: string): Promise<void>Deletes a folder made by create() that the plugin couldn't finish. This works only before the project is opened.
read(key: string, path: string): Promise<Uint8Array | null>Returns the file's bytes, or null if it doesn't exist.
write(key: string, path: string, data: string | Uint8Array): Promise<void>Writes the whole file, creating any missing parent folders.
remove(key: string, path: string): Promise<boolean>Deletes a file permanently (it doesn't go to the trash). Returns false if there was no such file.
list(key: string, path: string): Promise<{ name: string; folder: boolean; link: boolean }[] | null>Lists a folder's contents ('' for the project's folder itself), or returns null if the folder doesn't exist.
stat(key: string, path: string): Promise<{ folder: boolean; link: boolean; size: number; mode: number; mtimeMs: number; ctimeMs: number; ino: number; uid: number; gid: number; dev: number } | null>Returns information about a file or folder, without following symbolic links, or null if nothing is there.
mkdir(key: string, path: string): Promise<void>rmdir(key: string, path: string): Promise<boolean>Deletes an empty folder. Returns false if the folder isn't empty or doesn't exist.
arrived(key: string, paths: string[]): Promise<void>Tells the app that these files were changed from outside the app: they're marked as downloaded, and the open book reloads them.
note(key: string, note: { version?: { message: string; date: string }; push?: { ok: boolean; message: string } }): Promise<void>Reports a new version or the result of a push, so the dashboard can list it for the project.
app.library
The writer's books: those on the recent list, and every book in their series. Needs "library:read". API 2.
books(): Promise<LibraryBook[]>activity(): Promise<LibraryActivity>open(path: string, opts?: { select?: string }): Promise<boolean>Opens a book, closing the current one, optionally at a given document. Returns false if that fails.
app.net
fetch(
url: string,
init?: { method?: string; headers?: Record<string, string>; body?: string | Uint8Array },
): Promise<FetchResult>Makes an https request to a host the plugin may reach, and returns the whole response (on a computer, up to 20 MB within 30 seconds). Plain http works only for localhost and 127.0.0.1. Redirects aren't followed.
stream(
url: string,
init: { method?: string; headers?: Record<string, string>; body?: string | Uint8Array } | undefined,
onChunk: (text: string) => void,
): Promise<{ ok: boolean; status: number; statusText: string; headers: Record<string, string> }>Like fetch, but passes the response body to onChunk as text while it arrives, for example an AI model's reply. Resolves with the status and headers once the response is complete. Up to 200 MB and ten minutes. On a phone, the whole body arrives as one chunk. Chromium buffers the first 512 bytes of a text/plain response to detect its type, so they may arrive together unless the response has "X-Content-Type-Options: nosniff". Event streams and JSON aren't affected.
streamBytes?(
url: string,
init: { method?: string; headers?: Record<string, string>; body?: string | Uint8Array } | undefined,
onChunk: (chunk: Uint8Array) => void,
): Promise<{ ok: boolean; status: number; statusText: string; headers: Record<string, string> }>Like stream, but passes each chunk as raw bytes, for binary data. Up to 200 MB and ten minutes. API 10: check that it exists.
app.files
Files on the computer. The plugin can access only what the writer chose for it (with pickFolder and pickFile), and its own temporary folder. Needs "files:read" or "files:write". All paths are absolute.
pickFolder(opts?: { write?: boolean; title?: string }): Promise<string | null>Asks the writer to choose a folder, and returns its path or null. The plugin can then read what's in it, and change it if write is set and the plugin has "files:write".
pickFile(opts?: { save?: boolean; name?: string; extensions?: string[]; title?: string }): Promise<string | null>Asks the writer to choose a file to open, or where to save one if save is set. Returns the path, or null if they cancel.
granted(): Promise<{ path: string; write: boolean; file?: boolean }[]>temp(): Promise<string>The plugin's temporary folder, for passing files to programs.
read(path: string): Promise<Uint8Array>readText(path: string): Promise<string>write(path: string, data: string | Uint8Array): Promise<void>list(path: string): Promise<FileEntry[]>stat(path: string): Promise<{ folder: boolean; size: number; modified: string } | null>mkdir(path: string): Promise<void>trash(path: string): Promise<void>Moves a file to the system's trash.
app.exec
Runs programs that the manifest lists as "exec:<program>". Each is found by name on the PATH and runs without a shell. timeout is in milliseconds: one minute by default, ten minutes at most.
run(
program: string,
args?: string[],
opts?: { input?: string | Uint8Array; cwd?: string; timeout?: number },
): Promise<ExecOutput>app.permissions
The plugin's optional permissions (see the manifest's optionalPermissions). API 5: check that this exists before using it.
request(permission: string | string[]): Promise<boolean>Asks the writer to allow the permission, in the app's own window. Resolves to true if it's allowed, whether now or earlier.
has(permission: string): boolean | Promise<boolean>Whether the plugin has the permission now. In a sandboxed plugin, the answer comes as a promise.
app.speech
Speech recognition on the device: nothing is sent anywhere. On a computer it uses Whisper, whose model is downloaded once the writer agrees. On a phone or tablet it uses the system's recogniser. Needs "microphone", and isn't available to sandboxed plugins. API 4.
language is a code like "sv" or "en". Use '' to let a computer detect the language from the speech.
model selects the Whisper model on a computer. Each model is downloaded once:
- For every language: "tiny", "base", "small" (the default), "medium", "large-v3-turbo" or "large-v3".
- For English only: "tiny.en" to "medium.en".
- For Swedish only: "kb-tiny" to "kb-large" (KB-Whisper), or "pianissimo" (Klang's Pianissimo, API 5).
Each model is used with Silero voice activity detection, which detects where a phrase ends. A phone uses these models only when it uses Whisper instead of the system's recogniser (see SpeechChoice.engine).
status(language: string, opts?: SpeechChoice): Promise<SpeechStatus>Reports whether recognition is ready. If not, says what's missing: a download (size bytes, if known), or that it's unavailable here.
preload?(language: string, opts?: SpeechChoice): Promise<boolean>Loads the model ahead of time, such as when a book opens, so the first dictation is as fast as the rest. It only loads a model already on the device, and never downloads one. The model is unloaded after ten minutes without use. Returns true if it's ready. API 5: check that it exists before calling it.
prepare(language: string, opts?: SpeechChoice & { onProgress?: (fraction: number) => void }): Promise<boolean>Downloads what's needed, after asking the writer. Returns false if they decline.
listen(opts: SpeechChoice & {
/** Use '' to detect the language among `languages`, the app's language, the system's language and English. */
language: string
languages?: string[]
/** The current phrase, as recognised so far. */
onPartial?: (text: string) => void
/** Receives each finished phrase when the writer pauses. With onSegment, stop() returns only the text not yet passed to it. */
onSegment?: (text: string) => void
/** Called when something goes wrong. No more text will arrive. */
onError?: (message: string) => void
/** Receives the input level (0 to 1) several times a second, for showing that the microphone hears something. Older versions of the app don't call this. */
onLevel?: (level: number) => void
/** How long a pause ends a phrase: 'quick', 'balanced' (the default), 'patient', or a number of seconds. API 5. */
pause?: 'quick' | 'balanced' | 'patient' | number
/** The microphone to use, by its id from microphones(). Without one, the system's default is used. API 5. */
microphone?: string
}): Promise<SpeechSession>Starts listening and resolves with a session. The session's stop() returns the recognised text. On a phone, onPartial receives words as they're heard.
microphones?(): Promise<{ id: string; name: string }[]>The available microphones. Their names appear once the writer has allowed the app to use one. API 5.
ProjectFolder interface
A project folder, as returned by app.folder.
key: stringname: stringbook: stringThe open book's folder, relative to the project: books/<id>. Empty for a folder from folder.create.
VersionEntry interface
One version in a plugin's version history (see addVersionHistory).
id: stringThe plugin's identifier for the version. The app passes it back to read.
label: stringat: stringWhen it was saved, as an ISO date.
WaitInfo interface
What a during handler is told about the moment the app is waiting at.
words: numberThe number of words in the whole project.
changed: booleanWhether the project has changed since plugins were last told of a 'copy-due' or 'project-closing'. Always true for a new book.
quitting?: booleanOnly for 'project-closing': true when the window is closing, or the app is going to the background on a phone or tablet. Finish all work in the handler; don't leave anything for later.
reason?: 'timer' | 'new-book'Only for 'copy-due': 'timer' when the writing timer runs out and something has changed, 'new-book' when a book was just made.
Manifest interface
id: string2 to 64 lower-case letters, digits and dashes, starting with a letter or digit. It's also the name of the plugin's folder.
name: stringversion: stringdescription: stringauthor: stringapiVersion: numberThe plugin API version the plugin needs. Defaults to 1.
main: stringThe plugin's script, relative to its folder. Defaults to main.js.
sandboxed: booleanRuns the plugin in a separate worker instead of the app's window.
locales?: Record<string, { name?: string; description?: string }>The plugin's name and description in other languages, keyed by language code: { "sv": { "name": "…", "description": "…" } }.
optionalPermissions?: string[]Permissions the plugin can request later with app.permissions.request, when the writer uses a feature that needs them (such as sending text to a service). They take the same values as permissions, but the writer isn't asked for them when the plugin is turned on. API 5.
"network:ask" lets the plugin request access to an address the writer entered (such as a repository URL), which it can't list in advance. Request address:https://host/path: the writer is asked to allow that exact address, and the plugin can then reach that address and the paths under it. API 10.
permissionReasons?: Record<string, string | Record<string, string>>Why the plugin needs each permission in permissions or optionalPermissions, keyed by permission. The writer sees the reason when asked to allow the permission, under "it needs to:" and above the app's own description. Write it to complete the sentence "it needs to …", and say what is sent where, and why. Give one string, or one per language code, each up to 300 characters. API 8.
"permissionReasons": { "network:api.example.com": { "en": "fetch today's word from Example (api.example.com)", "sv": "hämta dagens ord från Example (api.example.com)" } }
category?: 'writing' | 'planning' | 'welcome' | 'import-export' | 'other'The group the plugin is listed under in Manage Plugins:
- "writing": tools for the text while writing
- "planning": the navigator, cards and views
- "welcome": the welcome screen
- "import-export": importing and exporting books
- "other": anything else
Without a category, the plugin is grouped by what it adds while it's turned on, and under "other" while it's off. API 8.
permissions: string[]What the plugin needs beyond reading the book. The writer is asked to allow each one:
- "project:write": change the book.
- "library:read": see the writer's recent books and their series (app.library), for the dashboard.
- "project:folder": read and change every file in the open project's folder, including hidden ones such as a version history (app.folder). Nothing outside that folder is accessible. API 10.
- "microphone": record audio with navigator.mediaDevices.getUserMedia, in the window. API 3.
- "network:<host>": connect to that host. Use "network:*.<host>" to include its subdomains, or "network:*" for any public host. "network:*" never covers this computer or the local network: name those hosts explicitly.
- "files:read", "files:write": read or change files and folders the writer chooses for the plugin.
- "exec:<program>": run that program, found by name on the PATH, without a shell.
NodeType type
type NodeType = 'text' | 'folder' | 'character' | 'place' | 'note' | 'research' | 'file'
NodeInfo interface
id: stringtitle: stringtype: NodeTypeparentId: string | nullchildren: string[]inTrash: booleanMetaInfo interface
synopsis: stringnotes: stringkeywords: string[]fields: Record<string, string>The fields on a character's or place's sheet: "Age", "Born"…
when: stringWhen the scene happens, as written on its card: "Day 3", "1888-05-01"…
words: numberLabel interface
id: stringname: stringcolor: stringStatus interface
id: stringname: stringcolor?: stringThe colour on the corkboard (#rrggbb) when cards are coloured by status.
FileEntry interface
name: stringpath: stringfolder: booleansize: numbermodified: stringExecOutput interface
code: number | nullThe exit code, or null if the program was stopped.
stdout: Uint8Arraystderr: stringtimedOut: booleantext(): stringstdout as text.
FetchResult interface
ok: booleanstatus: numberstatusText: stringheaders: Record<string, string>text(): stringjson(): unknownbytes(): Uint8ArrayLibraryBook interface
A summary of one of the writer's books, read from its files, for the welcome screen's dashboard.
path: stringThe book's folder. Pass this to app.library.open.
title: stringauthor: stringopened: stringWhen it was last opened in the app (ISO), or '' for a book in a series that's never been opened.
modified: stringWhen anything in the book last changed (ISO).
series: { name: string; path: string; index: number; books: number } | nullThe book's series: its name and folder, the book's zero-based position in it, and the number of books. Null if it isn't in one.
words: numberThe number of words and scenes in the manuscript.
scenes: numbertarget: numberThe word target (0 for none) and the deadline (YYYY-MM-DD, or '' for none).
deadline: stringsessionTarget: numberThe daily writing goal (0 for none).
history: Record<string, number>Words written per day, keyed by date (YYYY-MM-DD, in the writer's time zone). Empty for a book that isn't counted.
counted?: booleanWhether the book counts in the writer's statistics. It's false for a sample, or for a book or series the writer left out, so leave those out of totals and goals. Older versions of the app don't set it, so treat a missing value as true.
statuses: { name: string; count: number }[]The number of scenes with each status, in the order the book lists its statuses.
last: { id: string; title: string; modified: string; excerpt: string } | nullThe scene most recently written in, with the last few hundred characters of its text (as plain text).
LibraryActivity interface
Recent activity across the writer's books.
versions: { book: string; title: string; message: string; date: string }[]The latest saved versions (git commits), newest first.
backups: { file: string; date: string; size: number }[]The latest zip backups, newest first.
pushes: { book: string; title: string; ok: boolean; at: string; message: string }[]The most recent push of each book's version history, newest first.
SpeechChoice interface
Options for how speech is recognised. Pass the same options to status, prepare and listen.
model?: stringThe Whisper model (see app.speech).
processor?: booleanRuns Whisper on the CPU, even if a GPU is available.
engine?: 'auto' | 'system' | 'whisper'On a phone: 'system' uses the system's recogniser, 'whisper' uses Whisper, and 'auto' uses the system's where it supports the language.
EditorAnchor interface
A position in the text for inserting text over time. See app.editor.anchor.
docId: stringbefore(): stringThe character just before the position, to decide whether new text needs a space first.
after?(): stringThe character just after the position, to decide whether new text needs a space after it. API 5: check that it exists.
draft?(text: string): voidShows greyed-out words at the position, as dictation does. They aren't part of the text. Use '' to clear them. API 5: check that it exists.
insert(text: string): booleanInserts plain text at the position, after anything inserted earlier. Returns false if the document is no longer open in an editor.
release(): voidCall this when you're finished with the anchor. It also clears any draft.
SpeechStatus interface
ready: booleansize: numberThe number of bytes still to download, if known.
parts?: { title: string; size: number; model: boolean }[]On a computer, the parts of that download: the model itself (model: true) and the voice detection model. API 7: check that it exists.
SpeechSession interface
stop(): Promise<string>Stops listening and returns what was said.
cancel(): voidStops listening and discards what was heard.
pause?(): voidPauses listening and releases the microphone until resume() is called. Text recognised so far is kept. Older versions of the app don't have this, so check that it exists.
resume?(): voidEditorContext interface
What the writer right-clicked on in the text.
docId: stringselection: stringThe selected text, or '' if there's none.
word: stringThe word at the caret, when nothing is selected.
HighlightRange interface
A part of a paragraph to mark, given as character offsets in its text.
from: numberto: numbermessage?: stringShown as a tooltip when the pointer hovers over the mark, and in its right-click menu.
actions?: { id: string; label: string }[]Actions for the mark's right-click menu, such as "Ignore". The highlighter's onAction gets the chosen one. API 6.
quiet?: booleanHides the mark from the text and the right-click menu. ui.listMarks still lists it separately, with its actions. Use this for something the writer ignored, with an action to show it again. API 9: older versions of the app draw it like any other mark, so only use this when app.apiVersion is 9 or higher.
MarkInfo interface
The mark that an action was chosen for. API 6.
text: stringThe marked text.
paragraph: stringThe text of the paragraph it's in, as passed to find, and the mark's offsets in it.
from: numberto: numberdocId: stringThe document it's in.
ExportInput interface
The compiled book, passed to an export format.
title: stringauthor: stringlanguage: stringhtml: stringThe whole manuscript as one HTML document, the same as the app's own HTML export.
items: { id: string; title: string; depth: number; isFolder: boolean; section: 'front' | 'body' | 'back'; html: string }[]Each part in reading order: a folder's title, or a scene's title and text as HTML.
SettingField interface
key: stringlabel: stringtype: 'text' | 'secret' | 'textarea' | 'number' | 'toggle' | 'select''secret' is text shown as dots, for an API key or password (API 3).
description?: stringdefault?: unknownoptions?: { value: string; label: string }[]showWhen?: Record<string, string[]>Shows the field only while other settings have one of these values: { source: ['web', 'feed'] }. API 5.
folded?: stringPuts the field in a collapsed section with this heading, with any other fields that use the same heading. API 5.
PluginEvent type
type PluginEvent = 'project-open' | 'project-close' | 'selection-change' | 'doc-change' | 'nodes-change'
Suggestion interface
A suggestion offered as the writer types after a trigger.
label: stringinsert?: stringThe text that replaces the trigger and everything typed after it. Defaults to label.
detail?: stringImportFile interface
A file the writer picked to import.
name: stringext: stringThe extension in lower case, without the dot.
data: Uint8Arraytext: stringThe contents as text (UTF-8).
ImportSource interface
The file or folder the writer picked for a book importer. API 7.
name: stringIts name: "Sample.scriv", "outline.pltr".
ext: stringThe extension in lower case, without the dot.
folder: booleanTrue for a folder. On a phone, this is the folder inside the zip the writer chose.
data?: Uint8ArrayA file's contents as bytes and as text (UTF-8). Not set for a folder.
text?: stringfiles: { path: string; size: number }[]Every file in a folder, at any depth, with paths using "/". Empty for a single file.
read(path: string): Promise<Uint8Array>Reads a file in the folder, by its path in files.
readText(path: string): Promise<string>ImportedItem interface
An item in an imported book's binder. id is only for other items in the import to refer to it, such as a scene's cast or a beat's scene. The app assigns its own id. API 7.
id?: stringtype?: NodeTypeThe item's type. Without one, an item with children is a folder. Any other item takes the type of the navigator section it's in: a scene in the manuscript, a sheet in characters, a note in Notes, a document in Research.
title: stringhtml?: stringThe text as HTML: paragraphs, headings, emphasis, lists, quotes, and <hr> for a scene break.
synopsis?: stringnotes?: stringkeywords?: string[]label?: stringThe label and status, by their ids in the book's labels and statuses.
status?: stringincludeInCompile?: booleanWhether Compile includes the item. Defaults to true.
fields?: Record<string, string>Fields for a sheet ("Age", "Born"…), added to the fields the book already has.
when?: stringWhen the scene happens, as written on its card.
cast?: string[]The characters in a scene, and where it's set, by their item ids.
place?: stringfile?: { path: string; name: string }For a "file" item: its path in the picked folder, and the name to save it under.
children?: ImportedItem[]ImportedBook interface
The book that a book importer returns. The writer can make it a new book or add it to the open one.
As a new book, its labels and statuses, if any, replace the writer's defaults.
When it's added to the open book:
- The manuscript and research each go in a new folder.
- Characters and places are merged with the existing sheets, matching sheets by name.
- Labels, statuses and storylines are matched by name.
- The trash is left out.
API 7.
title: stringauthor?: stringabout?: stringA summary of what was imported, shown in the dialog before the writer chooses.
folder?: stringThe name of the new folders when adding to the open book: "From Scrivener — Sample".
labels?: { id: string; name: string; color?: string }[]statuses?: { id: string; name: string; color?: string }[]storylines?: { id: string; name: string; color?: string; description?: string }[]manuscript?: ImportedItem[]characters?: ImportedItem[]places?: ImportedItem[]notes?: ImportedItem[]research?: ImportedItem[]trash?: ImportedItem[]beats?: { storyline: string; scene?: string; title: string; description?: string }[]Beats (cards on the plot grid). Each names its storyline by id, and its scene by id if it belongs to one.