Skip to main content
Participant
April 1, 2021
Question

Does Illustrator support template literals?

  • April 1, 2021
  • 2 replies
  • 634 views

Hi,

 

I have an illustrator file with all of my icons, and a script that generates all the png assets for me. I would like it to also generate Contents.json files for iOS integration. In order to do that, I would like to utilize a feature like template literals, but I can't get it to work. I have tried with both 'let' and 'const' but the values don't update in the template. Any help would be greatly appreciated.

 

function mkContents(txt)
{
    let name = 'back';
    let size = '24';

    var Path = app.activeDocument.path;
    var saveFile = File(Path + "/" + "Contents" + ".json");

    if(saveFile.exists)
        saveFile.remove();

    saveFile.encoding = "UTF8";
    saveFile.open('w');
    saveFile.writeln(txt);
    saveFile.close();
}

let template = '''{
  "images" : [
    {
      "filename" : "ic_${ name }-${ size }@1x.png",
      "idiom" : "universal",
      "scale" : "1x"
    },
    {
      "filename" : "ic_${ name }-${ size }@2x.png",
      "idiom" : "universal",
      "scale" : "2x"
    },
    {
      "filename" : "ic_${ name }-${ size }@3x.png",
      "idiom" : "universal",
      "scale" : "3x"
    }
  ],
  "info" : {
    "author" : "xcode",
    "version" : 1
  }
}''';

mkContents(template);

  

This topic has been closed for replies.

2 replies

CarlosCanto
Community Expert
Community Expert
April 2, 2021

I've also seen developers use TypeScript which supports modern stuff, then transpile to ES3.

m1b
Community Expert
Community Expert
April 1, 2021

Hi, so you are running this as an ExtendScript targeting Illustrator? If so, it needs to be ES3, so write it like it was 1995. Which means only use 'var' not 'let' or 'const' and no template literals, just old-fashioned string concatenation. At a quick glance, it looks like those two changes should work in your code.

Disposition_Dev
Legend
April 3, 2021

i use const regularly. wish i could use let, though. =(