Skip to content
86% off$349 $48.86code BF2026

Docs

Bytepliers docs37 pages

Writing user scripts for Bytepliers

Write JavaScript transforms for Bytepliers: the scripts folder, headers, the state API, modules, sandbox limits, running from ⌘K and the CLI, and Boop scripts.

Updated 6 min read

On this page

Bytepliers scripts are your own JavaScript transforms. You can run them on a tool's input or on selected text, chain them in pipelines, call them from the command line, and reuse scripts you already wrote for Boop. This page covers the folder, the header and main function, the state API, modules, limits and how to run scripts.

What Bytepliers scripts can do

A user script is a .js file that takes text and returns new text. You run it from the User Scripts tool (in the Automate group of the sidebar) on the tool's input, or on the selections in an editor. You can also add it as a step in a pipeline or call it from the bytepliers command-line tool.

Scripts are Boop-compatible. They use the same header, the same state object and the same @boop/* module names.

Where scripts live and how to create one

By default, scripts are stored in:

text
~/Library/Application Support/Bytepliers/scripts/

When this folder is empty, Bytepliers installs 4 sample scripts: "Reverse Characters", "Count Characters", "Sort JSON Keys" and "Markdown Quote". It never overwrites them, so you can edit them.

Open the folder in any of these ways:

  • Help ▸ Open Scripts Folder
  • ⌘K (Command-K), then Open Scripts Folder
  • Open Folder in the User Scripts tool

To create a script:

  1. Open the User Scripts tool.
  2. Click New Script. Bytepliers creates "My Script.js" from a template and opens it in your default editor.
  3. Edit the script and save it.
  4. In Bytepliers, click Reload (⇧⌘R, Shift-Command-R) if the list hasn't picked up your change.
  5. Select the script in the Scripts list, add some input, and click Run (⌘R).
User Scripts tool with six scripts listed, Slugify Titles selected, three titles as input and URL slugs as output
Select a script and it runs live on the input.

Controls in the User Scripts tool

ControlWhat it does
LiveRe-runs the selected script as you type. On by default.
Run (⌘R)Runs the selected script.
Apply OutputReplaces the input with the output. ⌘Z undoes it.
Reload (⇧⌘R)Rereads the scripts folder.
Open FolderOpens the scripts folder in Finder.
New ScriptCreates a script from the template.

Right-click a script for Edit in Default Editor and Reveal in Finder. When you have text selected, the output pane title shows "· N selections".

Use a different folder

Open Settings (⌘,), choose Advanced, and under Scripts click Choose… next to Scripts folder:. Show in Finder opens the current folder, and Use Default switches back. Sample scripts are not installed in a custom folder. If the folder goes missing, Settings shows "Folder not found — using the default."

A custom folder is handy if you keep your scripts in a Git repository. Bytepliers has no sync, so a shared Git folder is the way to keep the same scripts on several Macs.

Write the header and the main function

Every script starts with a header that names it. Use either format.

JSON block (the Boop format). Trailing commas are tolerated:

js
/**
  {
    "api": 1,
    "name": "Wrap Lines in Backticks",
    "description": "Wraps every line in Markdown code backticks",
    "tags": "markdown,code",
    "bias": 0,
    "author": "Your Name"
  }
**/

function main(input) {
  return input.split("\n").map(line => "`" + line + "`").join("\n");
}

Comment lines (// @name, // @description, // @tags, // @bias):

js
// @name Trim Each Line
// @description Removes leading and trailing spaces from every line
// @tags lines,whitespace

function main(state) {
  if (state.text.trim() === "") {
    state.postError("Nothing to trim");
    return;
  }
  state.text = state.text.split("\n").map(line => line.trim()).join("\n");
  state.postInfo("Lines trimmed");
}

The entry point can take either style:

  • function main(input) returns a string. Good for simple transforms.
  • Boop-style main(state) changes state.text and can use the rest of the state API.

The argument is a String object that also carries the state members, so both styles work. A script without main fails with "The script must define function main(state)".

The state API

MemberWhat it does
state.textThe text to transform. Assign to it to change the result.
state.fullTextThe whole document. Reading it stops after the current selection; assigning to it replaces the whole document.
state.selectionThe current selection.
state.isSelectionWhether the script is running on a selection.
state.insert(text)Inserts text.
state.postInfo(msg)Shows a message in the status line or a HUD.
state.postError(msg)Shows an error and stops the script with no change.

With several selections, main runs once per selection. To make several selections in an editor, hold ⌘ while you drag.

Modules you can require

Use require() to load a built-in module or one of your own files.

ModuleNotes
@bytepliers/base64, @bytepliers/case, @bytepliers/csv, @bytepliers/format, @bytepliers/hashes, @bytepliers/html, @bytepliers/yamlBytepliers built-ins
@boop/base64, @boop/lodash.boop (also @boop/lodash), @boop/he, @boop/vkBeautify, @boop/js-yaml, @boop/hashes, @boop/papaparseBoop module names, for Boop scripts
A .js file in your scripts folderPath relative to the folder, for example require('lib/util')

Rules for your own modules:

  • The path must be relative to the scripts folder.
  • Absolute paths, ~, .. and symlinks that point outside the folder are refused.
  • Each module can be up to 2 MB.

npm packages can't be used.

Sandbox rules and limits

Each run gets a fresh JavaScriptCore context on a thread with an 8 MB stack, so nothing carries over between runs.

LimitValueMessage
Run time2 seconds"Timed out after 2 s (the script ran too long)"
Output size10 MB"Output is larger than 10 MB"
Script file size256 KB
Number of scripts200
Module size2 MB each

Scripts can't:

  • Make network requests (no fetch or XMLHttpRequest).
  • Use Node APIs.
  • Read or write files, or start processes.
  • Print to a console. console.* calls do nothing; use state.postInfo() for messages.

With Live on, the script re-runs on every edit. If you are working on a slow script, turn Live off and use Run (⌘R) instead.

Run scripts from ⌘K, pipelines and the command line

Command bar (⌘K). Your scripts are listed in the command bar. On a script row:

  • ⏎ (Return) runs it on the editor you were using, or on that editor's selections, as one undo step.
  • ⌘⏎ reveals the file in Finder.
  • ⌥⏎ (Option-Return) opens it in your default editor.

Pipelines. In the Pipelines tool, open Add Step ▸ Scripts and add a User Script step. Set its argument to the script's name. Each step's input can be up to 2 MB. Save the pipeline as a recipe to run it again from ⌘K, the menu bar, the Quick Panel or Shortcuts. The User Script transform isn't offered in the Compact Overlay picker.

Command line. Install the bytepliers command from Settings ▸ Integrations ▸ Command-Line Tool and open Bytepliers once so the CLI is enabled. Then run a script by name:

bash
echo 'hello world' | bytepliers script --arg "Reverse Characters"

This pipes the text into the "Reverse Characters" sample script and prints the result. The CLI only looks in the default scripts folder (~/Library/Application Support/Bytepliers/scripts/), not a custom folder chosen in Settings. If the script isn't there, you get "No script named “…” in <folder>".

Use your Boop scripts in Bytepliers

Bytepliers reads the same header, state API, @boop/* module names and bias field as Boop. Settings says it directly: "Boop scripts run unchanged."

User Scripts tool listing imported Boop scripts such as Collapse lines and Sort lines, sorting a list of cities
Boop scripts run unchanged.

Two ways to bring them over:

  1. Copy the .js files into ~/Library/Application Support/Bytepliers/scripts/, then click Reload (⇧⌘R) in the User Scripts tool.
  2. Or open Settings ▸ Advanced ▸ Scripts, click Choose… and select the folder where your Boop scripts already live.

Pick option 1 if you also want to run the scripts from the command line, since the CLI only reads the default folder.

Output from scripts that use formatting libraries can differ in style from what Boop's own libraries produce.

Troubleshooting

  • "The script must define function main(state)": the file has no top-level main function. Check the spelling, and make sure main isn't nested inside another block.
  • "The script returned nothing": a main(input) script ended without returning a string. Return a value on every path.
  • "Timed out after 2 s (the script ran too long)": look for an endless loop or work that grows fast with input size. Try a smaller input and turn off Live while you debug.
  • "Output is larger than 10 MB": split the input or produce less output.
  • A script doesn't appear in the list: click Reload (⇧⌘R). Check that the file ends in .js, is under 256 KB, and sits in the folder shown in Settings ▸ Advanced ▸ Scripts. The list holds at most 200 scripts.
  • require() fails: the path must be relative to the scripts folder and stay inside it.
  • The CLI can't find a script that works in the app: you are probably using a custom scripts folder. Copy the script into the default folder.

Every app.
One purchase.