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:
~/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:
- Open the User Scripts tool.
- Click New Script. Bytepliers creates "My Script.js" from a template and opens it in your default editor.
- Edit the script and save it.
- In Bytepliers, click Reload (⇧⌘R, Shift-Command-R) if the list hasn't picked up your change.
- Select the script in the Scripts list, add some input, and click Run (⌘R).


Controls in the User Scripts tool
| Control | What it does |
|---|---|
| Live | Re-runs the selected script as you type. On by default. |
| Run (⌘R) | Runs the selected script. |
| Apply Output | Replaces the input with the output. ⌘Z undoes it. |
| Reload (⇧⌘R) | Rereads the scripts folder. |
| Open Folder | Opens the scripts folder in Finder. |
| New Script | Creates 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:
/**
{
"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):
// @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)changesstate.textand 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
| Member | What it does |
|---|---|
state.text | The text to transform. Assign to it to change the result. |
state.fullText | The whole document. Reading it stops after the current selection; assigning to it replaces the whole document. |
state.selection | The current selection. |
state.isSelection | Whether 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.
| Module | Notes |
|---|---|
@bytepliers/base64, @bytepliers/case, @bytepliers/csv, @bytepliers/format, @bytepliers/hashes, @bytepliers/html, @bytepliers/yaml | Bytepliers built-ins |
@boop/base64, @boop/lodash.boop (also @boop/lodash), @boop/he, @boop/vkBeautify, @boop/js-yaml, @boop/hashes, @boop/papaparse | Boop module names, for Boop scripts |
A .js file in your scripts folder | Path 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.
| Limit | Value | Message |
|---|---|---|
| Run time | 2 seconds | "Timed out after 2 s (the script ran too long)" |
| Output size | 10 MB | "Output is larger than 10 MB" |
| Script file size | 256 KB | |
| Number of scripts | 200 | |
| Module size | 2 MB each |
Scripts can't:
- Make network requests (no
fetchorXMLHttpRequest). - Use Node APIs.
- Read or write files, or start processes.
- Print to a console.
console.*calls do nothing; usestate.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:
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."


Two ways to bring them over:
- Copy the
.jsfiles into~/Library/Application Support/Bytepliers/scripts/, then click Reload (⇧⌘R) in the User Scripts tool. - 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
mainfunction. Check the spelling, and make suremainisn'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.