Skip to content
Lauri-Matti Parppei edited this page Apr 28, 2022 · 3 revisions

Because Beat is sandboxed, the user has to confirm file access. Please don't try to do anything malicious.

Importing Data

Beat.openFile([extensions], function (filePath) { }) – displays an open dialog for an array of extensions and returns a path
Beat.openFiles([extensions], function ([filePaths]) { }) — as above, but allows selecting multiple files and returns an array of paths
Beat.fileToString(path) – file contents as string
Beat.pdfToString(path) – converts PDF file contents into a string

Exporting Data

Beat.saveFile(extension, function (filePath) { }) – displays a save dialog and returns the path to callback
Beat.writeToFile(path, content) – write a string to path

Examples

Reading files

Add file contents at the beginning of the current document.

let filename = Beat.openFile(["fountain"], function (filename) {
    if (!filename || filename.length <= 0) return

    let contents = Beat.fileToString(filename)
    Beat.addString(contents, 0)
})

Saving files

const string = "Hello World."

Beat.saveFile("txt", function (filename) {
    Beat.writeToFile(filename, string)
})