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:
Tell application "Adobe Illustrator"
do javascript "Macintosh HD/Applications/Adobe Illustrator CC 2018/Presets/en_US/Scripts/Submit_Files.jsx"
end tell
I have been searching and tinkering for hours to no avail. Can someone offer a pointer on what I might be doing wrong?
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
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
ilayer.locked = layerstate
}
}
// 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;
}
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
Copy link to clipboard
Copied
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".
Copy link to clipboard
Copied
Check the file path is correct.