run_lua_script
Execute custom Aseprite Lua scripts in batch mode for tasks no dedicated tool covers, such as procedural effects; print output to verify and call saveAs to persist changes.
Instructions
Execute arbitrary Aseprite Lua code in batch mode (last resort).
Reach for a dedicated tool first: draw_rows / read_rows to place and read pixels as text, draw_text for numbers and labels, replace_color or remap_colors_in_cel_range to recolour, export_animation or export_tag for GIFs, compare_frames and get_bounds to measure motion, view_sprite to look. Use Lua only for what none of them covers, such as a custom procedural effect. The full API is documented at https://www.aseprite.org/api/.
Essentials for batch-mode scripts:
When filename is given, it is opened first and available as app.activeSprite.
Changes are NOT saved automatically; call spr:saveAs(spr.filename) at the end if you modified the sprite.
print() is the only way to return data; a clean exit does not mean your logic succeeded, so print what you need to verify.
Coordinates on cel images are cel-local: offset sprite-global coordinates by cel.position before getPixel/putPixel.
WARNING: this executes unrestricted code (including io/os access) on the host running Aseprite. Only pass scripts you trust.
Args: script: Lua source code to execute filename: Optional Aseprite file to open before running
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"script": "<script>"
},
"name": "run_lua_script"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| script | Yes | ||
| filename | No |