run_script
Run ExtendScript in Adobe Illustrator on the active document to execute design code or .jsx files, pass arguments, use built-in recipes, retry failures, and return JSON results.
Instructions
Run ExtendScript in Illustrator on the active document in ONE call: a whole design in one script, details in small ones.
Give "code" (a function BODY: use return to get a value back as JSON; Illustrator objects come back as {type, uuid, name, box}) or "file" (a UTF-8 .jsx file with the same body; "args" are arguments[0..]). Non-ASCII text is safe in both.
ExtendScript is ES3: var only, no let/const/arrow functions/template strings, no Array.indexOf/map/forEach, no JSON object (use AIA.json / AIA.parse).
Errors return the message and the line number in your code. retries:n re-runs on MRAP or a "RETRY" result.
recipe: a built-in builder instead of code, options in args[0] (recipe:"list" names them).
Helpers (global AIA, always loaded; positions/sizes in session units, origin per configure — default pt, artboard top-left, y down):
AIA.layer(name) → get/create layer and make it active (new items go to the active layer) · AIA.fresh(name): same, emptied first (re-runnable builders)
AIA.group(name, parent?) → new GroupItem (parent = a Layer or GroupItem object)
AIA.swatch(name, color) → global process swatch (create/update); then use colour "swatch:Name"
AIA.pstyle(name, {font,size,color,leading,tracking,hscale,align}) → paragraph style (create/update)
AIA.text(str, {x,y,font,size,color,align,style,leading,tracking,hscale,name,parent}) → point text; y = BASELINE; "\n" = new line; align left|center|right (anchor at x)
Every helper takes its options as the LAST argument, an object; parent goes there (extra positional arguments are ignored).
AIA.rect(x,y,w,h,{fill,stroke,sw,name,parent}) · AIA.ellipse(x,y,w,h,{…}) · AIA.line(x1,y1,x2,y2,{stroke,sw,cap:"butt|round|square",dash,name,parent}) · AIA.path([[x,y],…],{closed,fill,stroke,…})
AIA.font(name) → TextFont, fuzzy ("Arial Bold" → Arial-BoldMT) · AIA.box(item) → [x,y,w,h] · AIA.mm(v) → pt · AIA.doc() → active Document · AIA.find(name)
AIA.refs(ref) → items for a uuid / "selection" / "name:X*" / "layer:X" / "artboard:N" · AIA.color(spec) → Color · AIA.colorStr(color) → spec
AIA.at(k, fn) → run fn with coordinates from artboard k's top-left (multi-artboard builders)
AIA.P(x,y) → document coordinates [x, y-up] for raw API calls · AIA.u(v) session units → pt · AIA.warn(msg)
Font size, leading, tracking and stroke width are always pt.
Colours as in every tool; "gray(60)" is K60 in CMYK documents.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "run_script"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| args | No | ||
| code | No | ||
| file | No | ||
| recipe | No | ||
| retries | No | ||
| timeout | No | seconds, default from configure (300) |