Quick Setup for After Effects Scripting

This article has been updated on Jan 29, 2022.

Overview

In this quick setup guide we will cover how to setup a basic scripting environment for both Mac and Windows. It will streamline your workflow by allowing you to code in your favorite text editor, and run your scripts from the Terminal (OSX) or Command Prompt (WIN) directly in After Effects via a simple command.

Note: This setup is Code Editor agnostic and is an alternative to using the deprecated Adobe ExtendScript Toolkit - if you are in need of ExtendScript debugging tools see: Extendscript Debugger in VS Code.

Let's Jump right in

Open you editor of choice. Let’s add a quick alert snippet - we will use this to check if the script is running properly once launched. Feel free to customize you alert message.

alert("Script OK");

Save the script as alert.jsx - notice the extension… After Effects scripts must have this extension in order to be run in AE.


MAC Setup

After Effects on Mac does not currently have the capabilities to run scripts directly via Terminal. We can remedy this with a quick workaround, by invoking the osascript command. OSA stands for Open Scripting Architecture, and it allows us to control a multitude of applications via scripting. The core scripting language used is Applescript - Apple’s own scripting language that allows you to automate tasks on your Mac OS - but Javascript and Objective C can also be used.

Osascript

In Terminal, type in the following command (we are using the Javascript language for this one):

osascript -l JavaScript -e "ae = Application('Adobe After Effects 2021'); ae.activate(); ae.doscriptfile('path/to/alert.jsx');" 
Launch the script in AE from Terminal.

So -l Javascript specifies the language we are using (default is Applescript), and our one line script is added after the -e flag; that specifies a statement.

Our one line Javascript code simply creates a variable ae that references the After Effects Application (specify the one you want, if available on your system). Then we open the specified version of AE, or focus on it if already open, by using activate(). Finally we run our .jsx script file using the doscriptfile() method.

Note: Make sure you specify your version of AE in the script. If you are not sure, navigate to your Applications folder or wherever your AE version is installed and check the version name there.

Find out the version name of AE by navigating to the folder where it's installed.

For launching even faster, without having to paste the code and amend every time for different versions, we've wrapped the osascript command above in a shell script - that allows us to simply specify the AE version number, and the .jsx script to launch. Check it out here:

GitHub - gfxhacks/ae-script-launcher: Launch a .jsx script in After Effects from the Command line.
Launch a .jsx script in After Effects from the Command line. - GitHub - gfxhacks/ae-script-launcher: Launch a .jsx script in After Effects from the Command line.

Applescript

As an alternative, we can write an Applescript and launch that using osascript. Open the Script Editor app or search for it in Spotlight. Then paste the following code, and save:

on run argv
	tell application "Adobe After Effects CC 2021" --specify your version of AE here.
		DoScriptFile item 1 of argv
	end tell
end run

Understanding the Applescript code

In essence, we are telling (tell) our version of After Effects to run the script (DoScriptFile) that we are specifying. The path to the script is retrieved from the argument (argv) that is passed once we will execute the code (in the next step...).

Let's move on by opening the Terminal app, then type in

osascript

Hit Spacebar once. Now drag and drop your Applescript file into the Terminal window. Next, repeat the drag and drop action but with your alert.jsx file instead.
Your command should look like this:

osascript path/to/yourApplescript.scpt “path/to/alert.jsx"

Note: The quotes that surround the jsx file path ensure that the path is passed as an argument and can be referenced inside the Applescript code (in our case it is passed to the DoScriptFile function that launches the script) - if you dropped a script file path containing spaces in your Terminal window, those spaces will be automatically escaped with a backslash: space\ here. Since we added the quotes already, we don't need to escape the spaces. But if we do, Applescript will assume that the backslashes are part of the file path so won't find your script. Make sure to remove any added backslashes within your quoted filepath.

Now hit Enter. After Effects should launch and, if all is working, it should run our alert.jsx script - you should receive an alert popup with the message you specified.

Alert popup in AE shows script launched successfully

That’s it!


WINDOWS Setup

On Windows, After Effects comes installed with an executable that can be used to run scripts via Command Prompt.

First locate the AE executable named AfterFX.exe. This should be found in C:\Program Files\Adobe\yourVersionOfAE\Support Files\ - replace yourVersionOfAE with your current version of After Effects e.g. “Adobe After Effects 2021”.

Open Command Prompt. Drag and drop the AfterFX.exe executable into the Command Prompt window then hit Spacebar and type -r, hit Spacebar again and repeat the drag and drop but this time with your alert.jsx file. Your command should look similar to this:

path/to/AfterFX.exe -r path/to/alert.jsx

Now hit Enter. After Effects should launch and, if all is working, it should run our alert.jsx script - you should receive an alert popup with the message you specified.

Alert popup in AE shows script launched successfully

Done!


Quick tips

Previous Command

In both Mac Terminal and Windows Command Prompt - you can call your previous command by pressing the up arrow key. Then Enter.

Command History

The following commands allow you to retrieve a list of previously executed commands:
MAC - in Terminal, type history and press Enter.
WIN - in Command Prompt press F7. Alternatively, type doskey /history and press Enter.


Extendscript Debugger in VS Code

Unless your code editor of choice is Visual Studio, you will be limited in debugging your scripts. Previously, only the Adobe ExtendScript Toolkit (ESTK - Adobe’s integrated development environment (IDE) for programming ExtendScript) offered debugging support, but it has since been deprecated, in favor of the VS Code version.

To install the VS Code ExtendScript Debugger refer to the Visual Studio Marketplace

For more information on how to get started with the VS Code Debugger check this guide: The VS Code Debugger


Editors


Update Notes

Jan 29, 2022