• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Javascript Error in AppleScript (Automator)

New Here ,
Jul 28, 2019 Jul 28, 2019

Copy link to clipboard

Copied

Hi Community,

I am trying to automate a workflow using Apple’s Automator program. I have a javascript that runs without issue when called from the File —> Scripts menu in Illustrator, but I get a cryptic error when I run the below workflow in Automator:

“Adobe Illustrator got an error: Error 25: Expected: ;.

Line: 1

->  Macintosh HD/Applications/Adobe Illustrator CC 2018/Presets/en_US/Scripts/Submit_Files.jsx”

My current workflow in Automator:

  • I manually identify the files I want to work with in “Ask for Finder Items”
  • “Open Finder Items” opens the files with “Adobe Illustrator CC 2018”
  • Next, “Run AppleScript” calls the JSX script:

               Tell application "Adobe Illustrator"

               do javascript "Macintosh HD/Applications/Adobe Illustrator CC 2018/Presets/en_US/Scripts/Submit_Files.jsx"

               end tell

  • I get the above error. As noted above, the script runs fine in Illustrator so I know the issue is with my AppleScript. I get the same error in the terminal.

I have been searching and tinkering for hours to no avail. Can someone offer a pointer on what I might be doing wrong?

TOPICS
Scripting

Views

1.7K

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
Contributor ,
Jul 29, 2019 Jul 29, 2019

Copy link to clipboard

Copied

Are you able to show us the code from Submit_Files.jsx?

There might be some error, which illustrator just ignores, and Automator don't

Votes

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
New Here ,
Jul 29, 2019 Jul 29, 2019

Copy link to clipboard

Copied

Yes here it is:

//  script.name = Submit_Files.jsx;

//  script.description = changes foil layer color to black and exports to pdf, it also exports ink layer to pdf

//  script.required = one or more open documents with FOIL and INK layers

// usage: open one or more documents before running the script. Once the script starts, it will change FOIL layer color items to black.

//              then, it will export FOIL layer to PDF, then it will export INK layer to PDF as well

function main () {

    var idoc, fname, newname;

    var blkColor = getThisColor([0, 0, 0, 100]);

       

    var foilLayer, inkLayer;

   

    for (var a=app.documents.length-1; a>=0; a--) {

        idoc = app.documents;

        idoc.activate();

       

        try {

            foilLayer = idoc.layers['FOIL'];

        }

        catch (e) {

            alert('FOIL layer was not found on document: ' + idoc.fullName.fsName);

            continue; // stops here and continues on next iteration of the loop

        }

        try {

            inkLayer = idoc.layers['INK'];

        }

        catch (e) {

            alert('INK layer was not found on document: ' + idoc.fullName.fsName);

            continue;

        }

        idoc.selection = null;

       

        var layerState = unlockAndUnhideLayers (idoc, true, false); // locked, visible

   

        foilLayer.visible = true;

        foilLayer.locked = false;

       

        app.executeMenuCommand('showAll');

        app.executeMenuCommand('unlockAll');

        app.executeMenuCommand('selectall');

       

        replaceColor (idoc, undefined, blkColor); // sourceColor, destColor

       

        restoreLayerState (idoc, layerState);

       

        // Hide Ink layer and export to pdf

        inkLayer.visible = false;

       

        fname = removeExtension (idoc);

        destFolder = idoc.path;

       

            // save as pdf

        preset = '[Illustrator Default]';

        destPath = destFolder + '/' + fname + '_FOIL.pdf';

        savePDF (destPath, preset);

       

        // Hide foil layer and export to pdf

        inkLayer.visible = true;

        foilLayer.visible = false;

       

        destPath = destFolder + '/' + fname + '_INK.pdf';

        savePDF (destPath, preset);

       

        }

    }

main();

function replaceColor (idoc, sourceColor, destColor) {

    if (sourceColor) {

        // choose the source color that will be changed

        idoc.defaultFillColor = sourceColor;

       

        //  select all object that has the color same source color

        app.executeMenuCommand("Find Fill Color menu item");

    }  

    //  change the color of selected object to dst color

    idoc.defaultFillColor = destColor;

    idoc.selection = null;

}

function removeExtension(idoc) {

    var f = idoc.fullName;

    var filename = idoc.name;

    var a_currentDoc = filename.split('.'); // get file name

    a_currentDoc.pop(); // remove extension

    return a_currentDoc.join('.'); // file name, without extension

}

function savePDF(filename, preset) {

//var obj = eval(params);

var idoc = app.activeDocument;

var pdffilename = filename;

var pdfFile = new File (pdffilename);

var pdfOptions = new PDFSaveOptions();

pdfOptions.pDFPreset = preset;

         pdfOptions.viewAfterSaving = false;

         pdfOptions.preserveEditability = false; // smaller file size

//alert(pdffilename);

//alert(obj.preset);

idoc.saveAs(pdfFile, pdfOptions);

}

function unlockAndUnhideLayers (doc, locked, visible) {

// get visible state of each layer, and show/unlock layers

var layerState = []; // array to hold layer visibility

var layerCount = doc.layers.length; // layer count

// get layer visibility, and turn all layers on

for (i=0; i<layerCount; i++) {

        var ilayer = doc.layers;

        layerState = [ilayer.visible, ilayer.locked];

        ilayer.visible = visible;

        ilayer.locked = locked;

}

    if (visible) {

        app.executeMenuCommand('unlockAll');

    }

    if (!locked) {

        app.executeMenuCommand('showAll');

    }

   

    return layerState;

}

function restoreLayerState(doc, layerstate) {

// restore layer visibility

    var layerCount = doc.layers.length; // layer count

for (k=0; k<layerCount; k++) {

var ilayer = doc.layers;

        ilayer.visible = layerstate[0];

        ilayer.locked = layerstate[1];

}

}

// create new cmyk color

function getThisColor (c /* array [46, 4, 1, 0] */) {

   

    var newColor = new CMYKColor();

    newColor.cyan = c[0];

    newColor.magenta = c[1];

    newColor.yellow = c[2];

    newColor.black = c[3];

   

    return newColor;

}

Votes

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 ,
Jul 29, 2019 Jul 29, 2019

Copy link to clipboard

Copied

Try:

set jsFile to POSIX file "/Applications/Adobe Illustrator CC 2018/Presets/en_US/Scripts/Submit_Files.jsx" 
tell application "Adobe Illustrator"
   do javascript jsFile
end tell

Votes

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
New Here ,
Jul 29, 2019 Jul 29, 2019

Copy link to clipboard

Copied

hhas01

Now I am getting the error:

"Adobe Illustrator got an error: Can’t get file "Macintosh HD:Applications:Adobe Illustrator CC 2018:Presets:en_US:Scripts:Submit_Files.jsx".

Votes

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 ,
Jul 29, 2019 Jul 29, 2019

Copy link to clipboard

Copied

LATEST

Check the file path is correct.

Votes

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