After Effects ExtendScript
Rules for ExtendScript in After Effects (jsx/aeft/): undo groups, the active composition, 1-based collections, and the version range.
Read host.md first: it explains AP.host.eval and how jsx/ is
loaded. This page is about code that runs in After Effects. Put code that only
makes sense in After Effects in jsx/aeft/.
Wrap every change in one undo group so the user undoes the whole action with
one Ctrl/Cmd+Z, and close it in finally:
app.beginUndoGroup("Rename layers");try { /* changes */} finally { app.endUndoGroup();}ap host eval already wraps each call in an undo group named
“AfterPresets agent”.
The active composition
Section titled “The active composition”app.project.activeItem is often null or not a composition (a footage item, a
folder, or nothing selected). Check before using it:
var comp = app.project.activeItem;if (!comp || !(comp instanceof CompItem)) { return JSON.stringify({ ok: false, message: "Open or select a composition first." });}Collections and times
Section titled “Collections and times”- Collections are 1-based:
comp.layer(1),app.project.item(1),comp.selectedLayers[0](a plain array, 0-based). - Times are seconds (floating point).
comp.frameDurationis one frame.
Versions
Section titled “Versions”The extension’s range is hosts[].minVersion in afterpresets.json (default
17.0, After Effects 2020). Check parseFloat(app.version) before using newer
APIs and return { ok: false, message } when they are missing.
Type hints
Section titled “Type hints”ap check --types checks jsx/ against the After Effects 26.0 declarations
from types-for-adobe and lists likely mistakes. Hints can be wrong; confirm
with ap host eval before changing working code.