photoshop_execute_script
Run custom ExtendScript (JSX) code in Photoshop to perform operations no existing tool covers. Returns the script's value as text/JSON.
Instructions
Execute custom ExtendScript (JSX) code inside Photoshop (advanced escape hatch).
Use when: no existing tool covers the operation and you can write safe JSX. Do NOT use when: a recipe or atomic tool exists — prefer photoshop_recipe_* or photoshop_* tools.
Returns: script return value serialized as text/JSON.
IMPORTANT: Your code runs inside a wrapping IIFE. Use an explicit return to pass data back — a bare trailing expression returns undefined. Example: return { ok: true }; Objects are serialized with toSource() and parsed automatically on macOS and Windows.
Preconditions: valid ExtendScript; active document if script expects one. Side effects: depends on code.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ExtendScript code to execute | |
| document_id | No | Optional Photoshop document id from photoshop_get_state / photoshop_list_documents. When set, the tool activates that document before running so a UI tab switch cannot retarget the edit. |