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

extend script convert to apple script

Participant ,
May 20, 2024 May 20, 2024

Copy link to clipboard

Copied

Hello,  could help me to convert below extend script to apple script, thanks.

 

Convert path of PDF to artboard.

 

#target illustrator

app.preferences.setBooleanPreference("ShowExternalJSXWarning", false);
var lines = {"x", "y", "g"}; 
var oldPdfName = lines [0];
var newPdfName = lines [1];
var folderPath = lines [2];
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; 
var pdfOptions = app.preferences.PDFFileOptions;
pdfOptions.pageRangeToOpen = "all"; 
pdfOptions.placeAsLinks = false;
var idoc = app.open(File(folderPath + "/" + oldPdfName), DocumentColorSpace.CMYK); 
app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS;

function getColor(pathItem) {
var isRightColor;
if (pathItem.strokeColor instanceof SpotColor) { 
var strokeColorName = pathItem.strokeColor.spot.name;
if (strokeColorName === "Diecut") {
isRightColor = "macColor"; 
}
else if(strokeColorName === "PFLW"){
isRightColor = "newPcColor"; 
}
}
return isRightColor;
}

var doc = app.activeDocument;
var artb = doc.artboards;
var artLayer = doc.layers[0];
var boardCount = artb.length; 
var glen = artLayer.groupItems; 


var pathColor;
var firstTopGroup = artLayer.groupItems[glen.length-1]; 
var firstGroupPaths;
if(boardCount === 1){ 
firstGroupPaths = artLayer.pathItems;
}else{
var firstClipGroup = firstTopGroup.groupItems[0]; 
firstGroupPaths = firstClipGroup.pathItems; 
}

for (var i = firstGroupPaths.length-1; i >=0; i--) {
var firstGroupPathItem = firstGroupPaths[i];
if (getColor(firstGroupPathItem ) === "macColor"){
pathColor = "macColor";
break;
} else if (getColor(firstGroupPathItem ) === "newPcColor"){
pathColor = "newPcColor";
break;
}
}
for(var u = glen.length-1; u>=0; u--){
var topGroup = artLayer.groupItems[u]; 
var paths;
if(boardCount === 1){ 
paths = artLayer.pathItems;
}else{
var clipGroup = topGroup.groupItems[0]; 
paths = clipGroup.pathItems; 
}

var whiteRectangles = [];
for (var i = paths.length-1; i >=0; i--) {
var pathItem = paths[i];
if (pathColor === "macColor"){
if(getColor(pathItem) === "macColor"){
if(pathItem.pathPoints.length === 4){
whiteRectangles.push(pathItem);
}else{
pathItem.remove();
}
}
}
else if(pathColor === "newPcColor"){
if(getColor(pathItem) === "newPcColor"){whiteRectangles.push(pathItem);}
}
else if(typeof pathColor === 'undefined'){
if(pathItem.pathPoints.length === 4){
if(pathItem.strokeColor.cyan == 0 && pathItem.strokeColor.magenta == 0 && pathItem.strokeColor.yellow == 0 && pathItem.strokeColor.black == 0){
whiteRectangles.push(pathItem);
}
}
}
}

if(whiteRectangles.length > 0){
for (var a=0; a<whiteRectangles.length; a++) {
whiteRectangles[a].selected = true;
var pathBds = whiteRectangles[a].geometricBounds;
whiteRectangles[a].remove();
artb.add(pathBds);
}}

}

for(var j=0; j<boardCount; j++){
artb[0].remove ();
}

function saveAsPDF() {
var pdfFile = new File(folderPath + "/" + newPdfName + ".pdf");
var pdfOptions = new PDFSaveOptions();
pdfOptions.compatibility = PDFCompatibility.ACROBAT5;
pdfOptions.generateThumbnails = true; 
pdfOptions.preserveEditability = true;
pdfOptions.preset = "[High Quality Print]"; //High Quality Print, Smallest File Size
app.activeDocument.saveAs(pdfFile, pdfOptions);
}
saveAsPDF();
doc.close();

 

TOPICS
Scripting

Views

346

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

correct answers 1 Correct answer

Engaged , May 21, 2024 May 21, 2024
quote

Hello,  could help me to convert below extend script to apple script, thanks.

 

Why? You can run your existing ExtendScript from AppleScript, e.g.:

 

test.jsx

alert('Hello ' + arguments[0])

 

test.scpt

property scriptPath : "/path/to/test.jsx" as POSIX file -- your path here

tell application "Adobe Illustrator"
  activate
  do javascript scriptPath with arguments {"Bob"}
end tell

 

Votes

Translate

Translate
Adobe
Engaged ,
May 21, 2024 May 21, 2024

Copy link to clipboard

Copied

quote

Hello,  could help me to convert below extend script to apple script, thanks.

 

Why? You can run your existing ExtendScript from AppleScript, e.g.:

 

test.jsx

alert('Hello ' + arguments[0])

 

test.scpt

property scriptPath : "/path/to/test.jsx" as POSIX file -- your path here

tell application "Adobe Illustrator"
  activate
  do javascript scriptPath with arguments {"Bob"}
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
Participant ,
May 21, 2024 May 21, 2024

Copy link to clipboard

Copied

You've been a great help. Thank you for sharing your knowledge and solving my problem.

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
Participant ,
May 22, 2024 May 22, 2024

Copy link to clipboard

Copied

hello, it is my first time to write apple script. I get the error: javascript code was missing. could you tell me where is wrong ? thanks

test.scpt
property scriptPath : "Macintosh HD/用户/china144/桌面/TEST/test.jsx" as POSIX file
tell application id "com.adobe.Illustrator"
activate
do javascript scriptPath with arguments {"foo", "bar"}
end tell


test.jsx
testFunc(arguments);
function testFunc(t) {
alert('argument one: ' + t[0] + '\r' + 'argument two: ' + t[1]);
}

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 ,
May 22, 2024 May 22, 2024

Copy link to clipboard

Copied

POSIX paths do not begin with the hard drive name. Try:

 

property scriptPath : "/用户/china144/桌面/TEST/test.jsx" as POSIX file

 

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
Participant ,
May 22, 2024 May 22, 2024

Copy link to clipboard

Copied

still be same error , do I need to install software to parse javascript code ?

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 ,
May 22, 2024 May 22, 2024

Copy link to clipboard

Copied

Your JavaScript is fine. The problem is your file path. If the file doesn’t exist, the `do javascript` command throws a “JavaScript code was missing” error. (The error message is misleading—it should say “file not found”.)

 

Here’s a useful tip: drag your `test.jsx` file from Finder into the Script Editor window. That will add the correct file path to your AppleScript code.

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
Participant ,
May 22, 2024 May 22, 2024

Copy link to clipboard

Copied

Thank you very much for your detailed and patient answer. I may need to change the system language to English and try again.

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
Participant ,
May 22, 2024 May 22, 2024

Copy link to clipboard

Copied

now I know how to solve the problem.
should be "do javascript file",
it is missing word "file"

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
Participant ,
May 24, 2024 May 24, 2024

Copy link to clipboard

Copied

LATEST

sorry,  actually you are right, there is no problem with the code, just set the security permissions with illustrator.

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