Scripting

The Divooka Motion Editor runs scripts written for After Effects: JavaScript files (.jsx or .js) that use After Effects' scripting objects - app.project, its items and compositions, layers, properties, keyframes, the Render Queue - and ScriptUI for windows and panels of their own. A script can build a whole composition, rename a hundred layers or render a batch of files, in one step you can undo.

Scripts are not expressions. An expression belongs to one property and works out its value on every frame (see the expression reference); a script runs once, when you start it, and changes the project.

Running a script

  • File ▸ Scripts ▸ Run Script File picks a script file and runs it.
  • File ▸ Scripts also lists the scripts that are installed, and choosing one runs it. Four come with the editor: Create Null at Selected Layers, Rename Layers, Render Queue Batch and Sort Layers by In Point.
  • File ▸ Scripts ▸ Install Script File copies a script into the editor's Scripts folder (in %APPDATA%\Divooka\Divooka Motion Editor), so it is listed from then on.

What a script prints, and the error it stopped at with its file and line, appear in the status bar at the bottom of the window.

Everything a script changes is undone with one Edit ▸ Undo when the script wraps its work in app.beginUndoGroup("Name") and app.endUndoGroup(), as After Effects scripts usually do; otherwise each of its changes is a step of its own.

A file of commands (.json or .jsonl) also runs from Run Script File: one {"command": "...", "params": {...}} a line, or an array of them, using the same commands as the command line and agents.

A first script

app.beginUndoGroup("Make a title");
var comp = app.project.items.addComp("Title", 1920, 1080, 1, 5, 30);
var bg = comp.layers.addSolid([0.1, 0.1, 0.2], "Background", 1920, 1080, 1);
var title = comp.layers.addText("Hello");
var position = title.property("ADBE Transform Group").property("ADBE Position");
position.setValueAtTime(0, [-300, 540]);
position.setValueAtTime(1, [960, 540]);
bg.Effects.addProperty("ADBE Gaussian Blur 2").property("Blurriness").setValue(20);
comp.openInViewer();
app.endUndoGroup();

Save it as Title.jsx and run it with File ▸ Scripts ▸ Run Script File: it makes a five-second composition of a dark blue background, its edges softened by a Gaussian Blur, and a title that slides in from the left over the first second, and opens it. Properties and effects are reached by After Effects' names - the match names such as ADBE Position or the names shown in the Timeline such as "Blurriness", as a script written for After Effects reaches them.

ScriptUI panels

A script can open windows of its own with ScriptUI: dialogs, which wait until they are closed, and palettes, which float over the panels while you go on working. A ScriptUI panel docks in the window like the editor's own panels.

File ▸ Scripts ▸ Install ScriptUI Panel copies one into Scripts\ScriptUI Panels. Installed panels are listed at the bottom of the Window menu; two come with the editor, Layer Tools and Ease Presets. Panels open when you quit open again at the next start.

The Script Console

Window ▸ Script Console is a prompt for scripting objects: type JavaScript and press Ctrl+Enter, or click Run, and it runs against the open project. Variables you make there last from one run to the next, so you can explore a project a line at a time:

var comp = app.project.activeItem;
comp.numLayers
comp.layer(1).name

The log above the prompt keeps each input, what it printed, its result and any error.

What a script may do

A script can read and change the project freely, and read files in the project's folder and its own. Writing files, reading files elsewhere, opening network connections and running other programs need Edit ▸ Preferences ▸ Scripting & Expressions ▸ Allow Scripts to Write Files and Access Network, which is off until you turn it on; a script cannot turn it on for itself. With Warn User When Executing Files on, the editor asks before a script opens a file in another program.

A script also cannot run or install other scripts through the editor's menus, start a watch folder or open Explorer, whatever it asks.

Starting the editor with a script

As with After Effects, -r runs a script file and -s runs a line of script once the editor has started:

DivookaMotionEditor.exe -r "C:\Scripts\Title.jsx"
DivookaMotionEditor.exe project.ecproj -s "app.project.activeItem.layer(1).enabled = false"

To run a script without opening the window at all, use the command line's script command; see Agents and the command line.

What is there and what is not

The scripting objects are After Effects' as Adobe documents them: the application, the project and its items, compositions, footage and folders, layers of every kind, properties and property groups with their values, keyframes, eases and expressions, masks, text documents, shapes, markers, the Render Queue with its items and output modules, import options, File and Folder, sockets, $, system and ScriptUI. A script written for After Effects that uses them runs here. A message to another program through BridgeTalk is refused, as there is no other Adobe program to answer it.

See also