Does Illustrator support template literals?

New Here ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

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);

  

TOPICS
Bug, Import and export, Scripting

Views

93

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

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.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

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

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

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

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines