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

Start

Building

Beyond Bläck Studio

How it runs

Sharing

Look up

Files and folders

With files:read or files:write, a plugin can use what the writer chooses for it, in the system's own dialog (its title starts with the plugin's name), and nothing else:

const folder = await this.app.files.pickFolder({ write: true, title: 'Where should the notes go?' })
if (!folder) return                                         // cancelled
await this.app.files.write(`${folder}/notes.md`, '# Notes\n')
for (const entry of await this.app.files.list(folder)) console.log(entry.name, entry.folder, entry.size)

const file = await this.app.files.pickFile({ extensions: ['csv'] })        // one file, to read
const target = await this.app.files.pickFile({ save: true, name: 'cast.csv' }) // where to save one

Choosing:

  • pickFolder gives the plugin a folder and everything in it. write: true lets it change what's there, if it has files:write; with only files:read, it reads what's there and nothing more.
  • pickFile gives it one file: to read, or with save: true to write.

Reading and writing (paths are full paths):

  • read returns bytes, up to 100 MB; readText returns text.
  • write(path, text or bytes) makes the folders on the way if need be.
  • list, stat and mkdir do what they say.
  • trash moves a file to the system's trash, where the writer can get it back.

Every path is checked in the main process, through any links: a link in a chosen folder that leads out of it leads nowhere. What the writer chose is kept until they take it back in Settings → Plugins, or turn the plugin off. granted() lists it.

temp() gives the plugin a folder of its own among Bläck Studio's data, that only the writer's account can open. It's always the plugin's to use, with any files: or exec: permission, for passing files to a program.