AE Scripting: How and Why.

I’ll start by saying this: After Effects can be a frustrating program. There are lots of usability features that should be built into the program by default. Adobe knows this, thankfully, and gives us the tools to add them ourselves by way of third-party extensions and scripts (via extendscript).

Products of After Effects scripting, on the surface, can sometimes feel like solutions looking for a problem. There’s room in every AE artist’s arsenal, though, for learning some basic scripting. We only have so many minutes– and equipping yourself with the mental toolkit to batch through layers and properties can help save some of those minutes.

Some of the ScriptUI panels I’ve written and use frequently.

My philosophy for AE scripting: Keep it small. Keep it light. Your screen real estate is valuable. Dockable scripts are only as useful as your willingness to keep them open all the time. Ask yourself: how much of my timeline am I missing out on because of this huge panel? How much is this do-it-all, feature-rich panel really doing for me? How many of these buttons do I actually use?

Keep it light. A script can be really specific. Let’s think about a scenario. You have 600 layers in your timeline. There’s a set of 120 layers that are track-matted (some are alpha, some luma, some inverted). You were in a time crunch, so you didn’t do a great job at renaming them, and you didn’t label them with colors. Oopsie poopsie. Also: a bunch of layers are locked. Luckily, you just need to select each set of two (the track matted layer and the layer above). You kinda want to avoid unlocking all the layers if you can because you spent a good amount of time locking a very specific set of layers.

  var l = app.project.activeItem.layers;
  for (var i = 1; i<= l.length; i++){
    if (l[i].trackMatteType !== TrackMatteType.NO_TRACK_MATTE){
      l[i].locked = false;
      l[i-1].locked = false;
      l[i].selected = true;
      l[i-1].selected = true;

This script is bad. It functions; it will do the job, but it’s bad. The reason it’s bad is because doing “i-1” in a for loop without really good error-catching can give you out-of-range syntax errors. Thankfully, though, this script will only ever operate on a layer that does have a track matte setting (and those will normally have a layer above– by design). (It will error out if you mistakenly have a layer that has a track matte set, but got dragged to the ‘1’ position in your layer stack. You could get around that particular instance by starting your for loop at 2. var i = 2; Try it.)

Flaws aside, the moral of the story is this: Make After Effects scripting work for you. If it’s gonna take at least 10 minutes to scroll through the layer stack and manually select those layers (with the ever-present danger of clicking incorrectly– or, gasp, accidentally double-clicking with all of those layers while selected), give yourself 5 minutes to jam together a script. This sort of scripting is what makes the language powerful.

If you equip yourself with an understanding of the basics — looping through all the layers in a composition, checking a certain aspect of the layer, and setting a mode according to that condition (shy, locked, enabled, selected), you’ll find that the reliance on scripts you can buy or download will dwindle. (And, honestly… how would you even begin a search to find a script that magically did exactly what the above scenario required, anyway?)

Scroll through the scripting documentation every once in a while to make a mental map of how to describe things via extendscript and commit a bit of syntax to memory. The less time you take looking stuff up is time saved. The question that’s always present when you travel down the path of writing a script is this: “Will doing this task the long/manual way take less time than writing and debugging a script?”

This blog will hopefully become a useful resource for people who know After Effects well enough to know where the holes are. My hope is that some of the words I dump on here will help us (me included) think critically about what features in a script are crutches [ways to avoid learning how to do things the long way disguised as automation]– or are simply gimmicks/clutter [over-engineered, multi-step processes that make you think you’re being efficient, but they just take up huge amounts of your screen space… because you feel guilty that you spent $29.99 for an entire script panel for that one button you use… like… twice a month. Whoa. Didn’t expect to rant that hard so soon.]

Published by thatsmadden

I'm an animation artist with an interest in code-driven motion.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with
Get started
%d bloggers like this: