64x64 icon dark hosting
Choose a hosting plan here and get a free year's subscription to Tuts+ (worth $180).

Introduction To The Basics Of After Effects Scripting


Start a hosting plan from $3.92/mo and get a free year on Tuts+ (normally $180)

To go along with our recent tutorial about script development workflow, we will go over the basic concepts and good practices necessary to start writing After Effects scripts. We will go over usual After Effects actions such as: creating a project, creating a composition, creating a layer, creating shapes, adding effects, changing values and expressions, using text and fonts, adding keyframes, using functions, etc.

Writing Your First Script

As stated in the After Effects Sublime Text build package installation and usage tutorial, scripts are files which use the Adobe ExtendScript language. ExtendScript is an extended form of JavaScript used by several Adobe applications such as Photoshop, Illustrator, and InDesign. ExtendScript is a good and efficient way to achieve anything you want in After Effects.

Scripts use the Adobe ExtendScript language, which is an extended form of JavaScript used by several Adobe applications such as Photoshop, Illustrator, and InDesign

This tutorial will go over the basic concepts and good practices necessary to start writing After Effects scripts.

Creating Our First Composition

We’ll start off by using the

method of the

object and wrapping it between curly brackets.


object is the root of almost everything as seen on this schema:

This schema can be found in the Adobe After Effects CS6 Scripting Guide like most of what I will explain in this tutorial.

We now create our composition by using the

object’s sub-objects

which contains the project created in the first line and the

sub-object which gives you access to the folders and compositions you see in your project window in After Effects.

Cleaning Our Code

Writing clean and maintainable code is really important. We are not writing quick and dirty expressions anymore. Since we want our scripts to be easily scalable, we need to embrace the Javascript community’s conventions.

So, we will isolate key data into variables and name them accordingly to their content. Also, we will put conditions in case there would already be a project or a composition in our After Effects file.


keyword indicates that the following variable is a new variable. That’s why, on line 9, we don’t use the

keyword anymore because we want to use

’s value (which is the comp we’ve just created).

Here’s, line by line, what we did in plain english:

  • Line 3: Create new variable

    which will equal to


    is not undefined and will otherwise equal to


  • Line 6: Create new variables


    which both equals to a new array of values.

  • Line 7: Create new variable

    which contains the name we will give to our comp.

  • Line 8: Create new variable

    which will equal to the

    property of our

    object. If it’s not undefined and will otherwise equal to the result of the

    method of the

    sub-object of

    to whom we’ll send an array of arguments containing:

    • Name of the composition
    • Width of the composition
    • Height of the composition
    • Pixel ratio of the composition
    • Time (in seconds) of the composition
    • Frame rate of the composition
  • Line 9: Use the


    which will open the timeline for this composition.

Yes, that’s a lot of methods and properties. Again, you will have to take a look at one time or another to Adobe After Effects CS6 Scripting Guide to learn more about the objects and their available methods and properties. The guide is really well written and a quick search for Project object will immediately take you to the right information.

Quick Javascript Concepts

  • Variable: Can store a value, an array of values or an object.
  • Array: Contains multiple values. Arrays can be declared in two ways.
  • Function: Part of code designed to perform a specific task.
  • Object: The object is a little more complex but, for now, you must know it has properties and methods.
    • Property: Similar to a variable
    • Method: Similar to a function call

Adding Undo Groups

Since a lot of operations will happen during your script execution, you’ll want to decide what will happen when you hit


Doing so it pretty easy, we just have wrap our code between the


methods of the

object. This method takes one argument which is the name that will be displayed in After Effects


Creating the Background Layer

To create our background layer, we will use the

sub-object of our

. Call the

method and send it these arguments :

Adding the Grid Effect

The best way to create our centered cross is by using the Grid effect on our background layer. To do that, we will use our

variable which refers to

and we will use its


There are some things your should notice here. First, the

method is chainable which means that you can call it multiple times to reach the sub-property you want to get.

  • : Layer’s opacity.

  • : Grid effect’s opacity.

Second, we use the method

when we want to set a value but not when we want to set an expression.

Creating the Wipe Layer

To add the wipe effect, we’ll create a new layer and use the Radial Wipe effect.

We used the method

to set keyframes and a

to make the animation loop (makes sense right?).

Adding the Text Layer

Playing with text is a little different since you have to change the source text value properties directly.

We changed our text value properties and used

to resend it to our text layer. Also, we used a simple expression to make our countdown.

is a Javascript function that will remove the decimal part of a number. After that we center the anchor point by using the


Adding the Ellipses

To add the ellipses we will use the

method and give it a vector group and a vector shape. We’ll also make a little function to avoid code repetition.

Line 5 is really important since you won’t be able to find the

property in neither the documentation nor in your After Effects interface for the moment, thanks to Dan Ebbert for his help (http://forums.creativecow.net/thread/227/22280).

We used a custom little function instead of duplicating the ellipse creation. You can use functions as you wish.

Basic rule of thumb: If you’re copy-pasting lines of code, consider using a function.

For the rest we just modified the shape’s properties. You may want to refer to Adobe After Effects CS6 Scripting Guide to see them listed.

You may have noticed the

line is looking a little different than what we’ve written yet. Javascript supports chaining across multiple lines. The result will be the same and there isn’t a good or bad way, it’s a personnal coding style choice you may or may not want to adopt.


The possibilities of scripting are endless and can make a really powerful tool once mastered. Here’s some more documentation about scripting and Javascript: