Skip to main content
willsc123
Participant
January 30, 2024
Question

Syntax Error when using Template String in script

  • January 30, 2024
  • 1 reply
  • 2311 views

Hello,

I'm creating a little After Effects panel with a button that adds an expression to the selected property. I'm trying to use Template Strings (String Literals or Template Literals, whatever is named) for the expression because I want to make it multiline and also interpolate variables into that expression.

 

For some reason, whenever I launch the panel from the Window menu, it gives me a "Syntax Error" message on whatever line that has the backticks (`) for the template string.

 

I know that template string are usable in expressions but, do they work in scripts or not? I thought that scripts would use Javascript as well.

 

I'm currently using AE 24.1.0 Build 78 on MacOS Ventura 13.5

 

Thanks in advance

This topic has been closed for replies.

1 reply

JohnColombo17100380
Community Manager
Community Manager
January 30, 2024

Hi @willsc123,

Template strings are not supported by scripting, though they are supported in expressions. Scripting and expressions use different versions of JavaScript; scripting uses ExtendScript, which is effectively ECMAScript3 with some Adobe-specific methods added, while expressions use modern JavaScript (at least ECMAScript 6).

 

You might be able to add the backticks to the expressions by using the character code at the time the expression is applied. That way it won't cause the scripting side to error.

 

Cheers,

- John, After Effects Engineering Team 

willsc123
willsc123Author
Participant
January 31, 2024

Oh, too bad to hear that! Are there any plans to upgrade the scripting engine to a more modern language?

 

I'll try what you suggest but I don't think it will work because I need the backticks on the script code, not on the expression. I wanted to use template string format for writing the expression string and interpolate variables from the script into the final expression, instead of writing the expression as an array and having to join all the lines.

 

I can workaround the problem with arrays, I just wanted a more concise and cleaner code.

 

Thanks for your help!

JohnColombo17100380
Community Manager
Community Manager
January 31, 2024

You shouldn't need backticks in the script code to apply them in the expressions, only inside the expression strings themselves. Take a look inside this script for applying expressions for animating variable width typefaces: https://github.com/AdobeDocs/after-effects/blob/fa149f419a7df53953b4208a17c2f20ea6d4db9e/samples/InspectVariableFonts_ApplyControls_ScriptUISample.jsx#L272. The linked function for building the expressions utilizes backticks and template strings, but is applied from ExtendScript.

 

We have investigated using a more modern scripting language for application scripting, similar to what Photoshop is using for extensions, but roadmap and planning aren't discussed publically for legal reasons.

 

I hope the script example is helpful,

- John, After Effects Engineering Team