Reply To: On the Move to InDesign: Formatting Text

Home Page / Forums / On the Move to InDesign: Formatting Text / Reply To: On the Move to InDesign: Formatting Text

#14323404
Jeremy Howard
Participant

Hello Silvio,

I’m glad to hear that you are getting into scripting! Instead of telling you how to run the ExtendScript that I wrote from AppleScript, I opted to write an AppleScript version. I added a comment to each line that explains how each line corresponds to the javascript that I posted before.

I hope this helps. Enjoy!

(*======================== BEGIN SCRIPT ==============================*)

tell application id “com.adobe.indesign” –Defining the application this way makes it “version proof” it will attempt to use the newest version of InDesign
repeat 1 times –Set to repeat once. This means that the script will only run through once but it allows us to use the “exit repeat” command to exit the script

if (count of documents) = 0 then –this if statement is the same as: if (app.documents.length == 0) ErrorExit(“Please open a document and try again.”, true);
display dialog “Please open a document and try again.”
exit repeat –Exits the repeat 1 times statement
end if

set myDoc to active document –SAME AS: var myDoc = app.activeDocument;
set myPageItems to every page item of myDoc –SAME AS: var myPageItems = app.activeDocument.allPageItems;
set imageFrameArray to {} –SAME AS: var imageFrameArray = new Array();

tell myDoc to ungroup every group — I had to add this because of the way that AppleScript interacts with the frames within a group

try –SAME AS: try{
set myDestLayer to layer “Images” of myDoc –SAME AS: var myDestLayer = myDoc.layers.add({name:”Images”});
on error –SAME AS: }catch(foo){
tell myDoc to set myDestLayer to make layer with properties {name:”Images”} –SAME AS: myDestLayer = myDoc.layers.item(“Images”);
end try –SAME AS: }

repeat with i from 1 to length of myPageItems –SAME AS: for(var i = 0; i < myPageItems.length; i++){
set aFrame to item i of myPageItems –SAME AS: var aFrame = myPageItems[i];

if class of aFrame = group then –SAME AS: if(aFrame == “[object Group]”){
set myGroupFrames to every page item of aFrame –SAME AS: var myGroupFrames = aFrame.allPageItems;
repeat with g from 1 to length of myGroupFrames –SAME AS: for(g = 0; g < myGroupFrames.length; g++){
set gFrame to item g of myGroupFrames –SAME AS: var gFrame = myGroupFrames[g];
–if the current frame is an image frame
if class of gFrame = rectangle or class of gFrame = polygon or class of gFrame = oval then –SAME AS: if(gFrame instanceof Rectangle || gFrame instanceof Polygon || gFrame instanceof Oval){
copy gFrame to the end of imageFrameArray –SAME AS: imageFrameArray.push(gFrame);
end if –SAME AS: }
end repeat — end repeat with g from 1 to length of myGroupFrames
else if class of aFrame = rectangle or class of aFrame = polygon or class of aFrame = oval then –SAME AS: }else if(aFrame instanceof Rectangle || aFrame instanceof Polygon || aFrame instanceof Oval){
copy aFrame to the end of imageFrameArray –SAME AS: imageFrameArray.push(aFrame);
end if –SAME AS: }
end repeat –SAME AS: }

repeat with x from 1 to length of imageFrameArray –SAME AS: for(x=0; x<imageFrameArray.length;x++){
set thisFrame to item x of imageFrameArray –SAME AS: var thisFrame = imageFrameArray[x];

try –SAME AS: try{
set myLinkedItem to page item 1 of thisFrame –SAME AS: var myLinkedItem = thisFrame.pageItems[0];
set myLinkName to name of item link of myLinkedItem –SAME AS: var myLinkName = myLinkedItem.itemLink.name;
set item layer of thisFrame to myDestLayer –SAME AS: thisFrame.itemLayer = “Images”;
end try –SAME AS: }

end repeat –SAME AS: }

display dialog “Finished.” –SAME AS: alert(“Finished.”, scriptName);

end repeat –End of the “repeat 1 times” statement
end tell

(*======================== END SCRIPT ==============================*)

This article was last modified on December 20, 2019

Comments (0)

Loading comments...