Getting Started with Scripting in After Effects
After Effects scripts are incredibly powerful — they can automate repetitive tasks, perform complex calculations, and even use some functionality not directly available in the After Effects interface.
While powerful, creating scripts for After Effects can be intimidating. Seeing those polished products for purchase on AE Scripts, I know I felt like scripting was out of my league.
On a recent project, though, I was stuck with a repetitive task for which I just knew a script would be great. I couldn’t stand the thought of wasting a ton of time throwing a © in the corner of hundreds of videos, each in a separate project file.
That afternoon, I did a lot of Googling and managed to hack together my first script — I felt so accomplished!
Looking back on the hunt I went through, just to write this first script, I wanted to assemble some resources here, so you don’t need to scour the internet for the same necessary information.
Before we get into the nitty-gritty, though, I also want to offer some advice if you, too, are timid to start scripting like I was.
Learn Some Javascript
If you’ve played around with expressions in After Effects, then you already know some basic Javascript! The Adobe ExtendScript language is just an extended form of JavaScript.
While expressions and scripts share the same language, there are some apparent differences. Expressions are created inside of After Effects and are written directly on the properties of individual layers. They are typically used to connect or control layers. Scripts, on the other hand, are like little programs that you choose to run to perform a specific, pre-determined task. You’ll generally see these used as extra windows or buttons you can add to the After Effects UI.
A less intimidating way to get started with ExtendScript/Javascript is to learn how some more complex expressions work.
wiggle () and loopOut () are fun and useful but are just the tip of the iceberg. Try practicing your coding skills with a few of these exercises:
Make a responsive text box with SourceRectAtTime().
Use if-else statements to turn a layer on and off with a checkbox.
Learn to link things between compositions with some control effects (checkbox control, color control, slider control).
Evan Abrams and Jake Bartlett both have great tutorials on these and many other expressions that can get your feet wet.
If you ever get stumped creating something from scratch, there are plenty of ExtendScript/Javascript resources available (A handy list of my go-to resources is available at the bottom of this page.) Just know — ExtendScript is based on a very old version of Javascript, so the latest and greatest Javascript tricks may not apply — but the foundations are the same.
Start simple
With any project, I frequently have to remind myself to keep things manageable. Coding especially is a lot of trial and error. The more code you have, the more potential for mistakes.
When you’re first getting started, start simple — even if your ambitions are high. I bet you remember when you first opened After Effects. The sky is the limit! Until you learn, you need to rein things back based on your skill level.
Take a look at a few tutorials and resources and write a few lines of code to start. Here’s a peek at my first script — just three lines of code!
var selectedComp = app.project.activeItem;
var copyright = selectedComp.layers.addText("©");
copyright.position.setValue([1880,1060]);
Originally I had hoped to figure out how to set a specific font, size, weight, and so on. But I decided to just set the character panel and keep my simple — but a working script.
Is it worth the time?
I enjoy a good puzzle, which is why I can easily get pulled into coding. It’s a huge rush to get something working after tinkering for hours. Before you get pulled in, though, make sure you ask — will creating a shortcut for this task be quicker than the time it would take to do it all manually?
It can be hard to predict how long a new challenge will take, so set yourself a time limit — how much time can you afford before breaking down and doing it the tedious way?
If you get stuck or run out of time, think about going back to it later when you’re not on the clock to see if you can use it in the future.
Hopping in
So, you’re ready to hop in and make your first script. Here are a few steps to get you started.
ExtendScript Toolkit
First, you’ll want to acquire ExtendScript Toolkit (available through your Adobe Creative Cloud subscription) or another program that makes it easier to write your code.
ExtendScript Toolkit is an older program, so you won’t immediately see it in the line up of Creative Cloud applications. To get the option to download it, head over to your Preferences, then Apps. Scroll down to the bottom, and you’ll find an option to Show Older Apps. Now, it should be available for download.
If you have any trouble finding the app, below are some older download links —
And if you don’t want to download ExtendScript Toolkit, you can technically use any code text editor or plain text document. You just won’t get the same integration with After Effects or debugging help. My favorite free code text editor is Sublime. If you still want ExtendScript debugging, I’ve read that some folks use Visual Studio Code with the Adobe ExtendScript debugger extension (though I’ve never used this personally).
Attributes
Once you have the tools to write with, you need to know what to write!
That’s where this extensive documentation on scripting in After Effects comes in handy. This document lists every possible attribute available to you (called as such to avoid confusion with After Effects properties — the typical word used in coding).
All of this can be overwhelming at first, but luckily the document is searchable.
By searching for text, I found information on TextLayer object — by reading the description, I get a link to the code I need to create a text layer. It’s a little convoluted, but you will get the hang of it!
Once you’ve coded a bit, it’s time to test what you’ve written. To start, open After Effects, select the version of AE in the dropdown menu of ExtendScript Toolkit, and hit the run button.
Any errors are highlighted, and the script is executed in After Effects — so take a look to see if it did what you intended!
Bring it into AE
If your script is working as intended, it’s time to save it as a .jsx file and get it into After Effects.
There are two ways to do this. If you know where your scripts folder is, go ahead and save it right in there. Otherwise, you can go ahead and install it by selecting File > Scripts > Install Script File….
For a simple script like I showcased above, I suggest using a tool like KBar for easy access. Otherwise, you’ll have to pop back into the scripts menu each time you want to use them — and these are meant to save you time, right?
Happy coding!
Don’t stress too much about being a coding genius. It’s just another useful skill to have as an animator — not a requirement.
To help you get started, I’ve assembled a list of resources I found useful in my journey to learn a bit of coding.