Skip to content

Scripting & Automation

Automate FrameRef with Luau scripts, reusable plugins, and a local automation server.

FrameRef includes a Luau scripting system for automating board work. Use it for one-off cleanups, batch edits, reusable plugins with their own menu actions, or external tools that drive FrameRef over a local connection.

Scripting is enabled by default. The main entry point is the Scripts menu, which contains:

Action Description
Script Console Open the multi-tab script editor.
Run Script File… Run a .luau or .lua file without opening the console.
Reload Scripts Reload all script plugins from disk.
Open Scripts Folder Open the folder where user plugins live.
Export Scripting Stubs… Write frameref.d.luau for editor completion.
MCP Integration… Configure the local MCP server.

Open the console with Scripts → Script Console or Ctrl + Alt + J. It is a regular FrameRef window, so you can move, resize, maximize, or keep it next to the board.

The console provides:

  • Multiple editor tabs so several scripts can stay open at once.
  • Luau syntax highlighting and completion, including type annotations.
  • Templates for common tasks.
  • Recent scripts for quickly reopening files you used before.
  • An output panel for print, errors, return values, and timing.
  • A Quick Help panel with a compact API reference.
  • Whitespace display, editor zoom, and session restore between launches.
Action Default shortcut
New Script Ctrl + N
Open Script Ctrl + O
Save Script Ctrl + S
Save Script As Ctrl + Shift + S
Close Script Tab Ctrl + W
Run Script F5
Run Selection Shift + F5
Clear Output Ctrl + L
Quick Help Ctrl + Shift + H
Toggle Output Panel Ctrl + Shift + O

These shortcuts can be changed in Preferences → Script Editor.

Scripts run against the active board and use the global frameref object. A script can return any JSON-serializable value. print(...) messages and return values appear in the output panel.

Count the images on the active board:

local count = 0
for _, item in frameref.items.all() do
if item.type == "image" then
count = count + 1
end
end
return { images = count }

Tag every selected item:

local items = frameref.selection.items()
for _, item in items do
item:addTags({ "reviewed" })
end
return { updated = #items }

Find items by type, tag, label, or UID:

local references = frameref.items.find({
type = "image",
tags = { "character" },
limit = 50,
})
for _, item in references do
item.rating = 5
end

Every console run is applied to the board as one undoable step. A script that edits many items still undoes with one Ctrl + Z. Plugins can group their own work explicitly with frameref.undo.begin("Label") and frameref.undo.commit().

frameref.input.form shows a modal form and returns a future:

local values = frameref.input.form({
title = "Create note",
text = "Where should the note go?",
fields = {
{ key = "x", label = "X", type = "int", default = 0 },
{ key = "y", label = "Y", type = "int", default = 0 },
},
}):await()
if not values then
return
end
frameref.items.createNote({ x = values.x, y = values.y })

The frameref table is organized into namespaces. For every function, parameter, return value, and object property, see the Scripting API Reference.

Namespace What it does
frameref.boards List open boards, get the active board, and activate another board.
frameref.selection Read and change the selection.
frameref.items Find, create, import, duplicate, delete, group, arrange, align, and distribute items.
frameref.actions List registered actions, run them, and change their shortcuts.
frameref.undo Begin, commit, or cancel an undo group, and drive undo/redo.
frameref.events Subscribe to board and selection events. Plugins only.
frameref.async Defer work or run a callback after a delay. Plugins only.
frameref.storage Store JSON data per plugin. Plugins only.
frameref.settings Read and write allowlisted preferences.
frameref.project Inspect and save the current project.
frameref.clipboard Copy, cut, and paste items.
frameref.image Capture an item as an image.
frameref.input Show a form and await the result.
frameref.search Search the active board for items and actions.
frameref.log, frameref.notify Write to the output panel or show a notification.

Items returned by the API are live handles, not copies. Read and write properties directly, or use the methods for operations that need an undo command:

local item = frameref.items.get("<uid>")
if item == nil then
error("Item not found")
end
item.label = "Hero pose"
item.rating = 4
item:addTags({ "approved" })
item:moveBy(20, 0)

Every item exposes the base properties uid, type, label, caption, tags, rating, x, y, rotation, scale, width, height, z, opacity, locked, visible, and sourceURL. Some types also expose properties of their own, such as muted on video and audio items or currentShape on shapes; see Item properties for the full list by type. Common methods include addTags, removeTags, delete, duplicate, select, frame, moveBy, moveTo, rotateBy, rotateAround, scaleBy, scaleAround, capture, awaitReady, isValid, and snapshot.

frameref.boards.list() returns every open board, so a script can work across tabs:

for _, board in frameref.boards.list() do
local snapshot = board:snapshot()
print(snapshot.title, #snapshot.items)
end
frameref.boards.active():save()

Board properties are read-only: id, title, path, readOnly, and dirty. Methods include items, selection, snapshot, save, saveAs, undo, redo, frame, and activate.

for _, result in frameref.search("cover") do
print(result.kind, result.title, result.description)
if result.kind == "navigation" then
result:activate()
end
end
frameref.actions.run("action_select_all")

Plugins turn scripts into reusable actions with names, shortcuts, and optional event subscriptions. A plugin is a folder inside your scripts folder:

MyPlugin/
plugin.json
main.luau
helper.luau

plugin.json describes the plugin:

{
"id": "com.example.myplugin",
"name": "My Plugin",
"version": "1.0.0",
"api": 1,
"main": "main.luau",
"permissions": ["scene.read", "scene.write"],
"actions": [
{
"id": "tag-selection",
"title": "Tag Selection",
"tooltip": "Add the review tag to every selected item",
"shortcut": "Ctrl+Alt+T"
}
]
}
  • id must be unique.
  • api is the plugin API version. Use 1.
  • main points to the entry file.
  • permissions controls what the plugin may do. scene.write allows board changes; * grants everything. A plugin without scene.write runs read-only.
  • actions becomes the plugin’s Scripts menu entries and shortcut actions.

main.luau returns a table of action functions:

local helper = require("helper")
return {
actions = {
["tag-selection"] = function(ctx)
local items = frameref.selection.items()
for _, item in items do
item:addTags({ "review" })
end
frameref.notify(string.format("Tagged %d item(s)", #items))
end,
},
}

The ctx argument contains pluginId, actionId, pluginName, and dataDir. require("helper") loads a Luau file relative to the plugin folder. Modules are cached for the plugin environment.

Plugins can subscribe to events and keep data between runs:

local subscription = frameref.events.on("selection.changed", function(boardId)
frameref.log("Selection changed on " .. boardId)
end)
frameref.storage.set("lastRun", os.date())
frameref.storage.save()
frameref.async.delay(2.0, function()
frameref.events.off(subscription)
end)

Available events are board.activated, board.opened, board.closed, board.saved, selection.changed, scene.changed, undo.changed, and project.changed.

Futures and callbacks are covered in detail under Async and futures, including when to use :await() and when to use :andThen() and :catch().

New plugins ask for permission the first time they are seen. The prompt lists the requested permissions, and FrameRef remembers a SHA-256 hash of the manifest. If the manifest changes, the plugin asks again.

Plugins are loaded from:

  • The user scripts folder (Scripts → Open Scripts Folder).
  • Any extra folders in Preferences → Scripting → Script search paths.

Previously approved plugins can load automatically at startup. Turn that off with Load trusted plugins on startup.

The automation server exposes a local WebSocket JSON-RPC endpoint for editors and other tools. It is disabled by default.

Enable it in Preferences → Scripting → Enable automation server. Leave the port at 0 to choose a random loopback port, or set a fixed port.

When the server starts, FrameRef writes a discovery file:

Platform Path
Windows %APPDATA%\Polygonflow\FrameRef\automation\server.json
macOS ~/Library/Application Support/Polygonflow/FrameRef/automation/server.json

The file contains the port, a per-session bearer token, the process ID, and protocol and app versions. Connect to ws://127.0.0.1:<port> and send the token in an Authorization: Bearer <token> header or a ?token= query parameter.

Method Description
api.info App version, API version, active board, open boards, and whether scene edits are allowed.
script.run Run Luau from a source string or a file inside the configured script search paths. Logs are streamed as script.log notifications.
script.cancel Interrupt the current script.
stubs.get Return the generated frameref.d.luau stubs.
scene.snapshot Return a snapshot of the active board.

Remote scripts are read-only by default. Enable Allow remote scripts to edit the board to let them change the board. The same setting is used by the MCP integration, so turning it on enables writes for both.

The server binds to 127.0.0.1 only. Requests with a browser Origin header are rejected, and the bearer token is required for every connection.

Connect to ws://127.0.0.1:<port>, send the bearer token, and use JSON-RPC messages:

{"jsonrpc": "2.0", "id": 1, "method": "api.info"}
{
"jsonrpc": "2.0",
"id": 2,
"method": "script.run",
"params": {
"source": "return { items = #frameref.items.all() }",
"filename": "remote-count"
}
}

Script logs arrive as script.log notifications while the request runs.

FrameRef can generate a Luau definition file for editor completion and type checking:

  1. Open Scripts → Export Scripting Stubs…
  2. Choose a folder. FrameRef writes frameref.d.luau there.
  3. Point your editor’s Luau language server at the file.

The stubs include the frameref namespaces, item and board handles, events, futures, and the live list of action IDs.

  • Scripts run in a sandbox. One-off scripts cannot use require, io, load, or arbitrary file and network access. Plugins can use require for modules inside their own folder.
  • The automation server and MCP server listen on loopback only and authenticate with per-session tokens.
  • Remote writes are disabled until you turn them on.
  • Plugin trust is tied to a manifest hash. Changing the manifest requires approval again.
  • Every run has a timeout. The default is 10 seconds; the allowed range is 0.5 to 120 seconds.
  • Every run is one undoable step, including plugin actions.
Problem Fix
Scripts menu actions are disabled Check Preferences → Scripting → Enable scripting.
A plugin does not appear Confirm the folder contains a readable plugin.json and the main file exists. Then use Scripts → Reload Scripts.
A plugin cannot change the board Add scene.write to its manifest permissions and approve the updated plugin.
A script stops with a timeout Narrow the work, add filters to items.find, or raise the timeout in preferences.
The automation client cannot connect Enable the automation server, check the discovery file, and use the current token.