I'm trying to learn about After Effects' different abilities.


If I make a function using extend script like so

function alertStuff() {

Can I call this using a layer expression?


2 Answers 2


Short answer: no.

Long answer: There may be an unknown, undocumented hack that enables this, like modifying some of the core classes, or a workaround, like writing to a file and reading the results, but I've never heard of such a thing.

You probably know this, but it might be worth spelling out the differences between the two.

Expressions are evaluated every time a frame is rendered, either during preview or final render (this can be multiple times per frame when motion blur is turned on). They can access the properties of layers and compositions and other project items, as well as making some system calls and reading external files and a few other undocumented JS functions like time and date. They can not change any part of the project, they are limited to returning one value—the value applied to the property they belong to.

This is different to the way scripts work, which is to basically replicate anything the user could do, but programatically. They are not called at render time. Since scripts can change the content of compositions, there would be problems with calling them at render time: just using your example, the alert might be displayed 64 times per frame if motion blur was set really high—that would get old pretty quickly. But even for a non-trivial example: suppose you had a script that added a layer to the current comp. If it was called from an expression it would run every time the frame was rendered, whether it was at final render time, or during previewing, or when the user parked the playhead on the frame. With MB on that could mean 64 new layers could be added per frame—while the comp was being rendered. The results would get pretty messy.


You can read/write the expressions from ExtendScript ;) For example for changing placeholders:

var propertyExpression = property.expression;
if (property.expressionEnabled && propertyExpression) {
  try {
    property.expression = propertyExpression.replace(new RegExp(placeholder, 'g'), 'string for replacement');
  } catch(e) {

I had to make 6 nested loops to get into all expressions... (The layers have properties, which have sub properties, which also have sub properties, ...)

So I guess you can insert alert("stuff") directly into an expression.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.