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();
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
You've been a great help. Thank you for sharing your knowledge and solving my problem.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
still be same error , do I need to install software to parse javascript code ?
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.
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.
Copy link to clipboard
Copied
now I know how to solve the problem.
should be "do javascript file",
it is missing word "file"
Copy link to clipboard
Copied
sorry, actually you are right, there is no problem with the code, just set the security permissions with illustrator.