photoshop_execute_script
Run custom ExtendScript (JSX) code inside Photoshop when no built-in tool covers the operation. Returns the script result as text or JSON and supports long-running jobs via a custom timeout.
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.
Long scripts: pass timeout_ms (up to 600000) so the default 30s budget does not kill the job.
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 | |
| timeout_ms | No | Script timeout in milliseconds (default 30000, max 600000). Override with env PHOTOSHOP_SCRIPT_TIMEOUT. Use for long loops, batch jobs, or large documents. | |
| 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. |