Skip to main content
Inspiring
January 11, 2012
Answered

Lost in translation (AS to JS)

  • January 11, 2012
  • 2 replies
  • 1264 views

hello all,

I have written an applescript, but i need to convert it over to JavaScript for compatibility with a 3rd party pugin.

i am having a little trouble translating the following section of code from AS to JS.

tell application "Adobe InDesign CS5"

         set DocumentLinks to the file path of every link of active document

end tell

So far i have the following in JS:

var documentLinks = [];

var myDocument = app.documents.item(0);

for (var myCounter = 0; myCounter < myDocument.allGraphics.length; myCounter++){

var myGraphic = myDocument.allGraphics[myCounter];

var myLink = myGraphic.itemLink;

var myPath = myLink.filePath;

var documentLinksCount= documentLinks.push(myPath);

}

When i try to run this with a specific indesign document, i get the error "null is not an object" and the "var myPath = myLink.filePath;" line is highlighted.

I think this error is occuring because "myDocument.allGraphics.length;" has a value of 19 with this document but when i look at the links pallette manually in indesign, I only see 18 links.

so somehow i have an image on the page that has a null path that is causing my script to error.

can anyone tell me the best approach to bypassing this issue?

Thanks!

This topic has been closed for replies.
Correct answer Harbs.

Sorry, my code had an error:

var documentLinks = app.activeDocument.links.everyItem().filePath;


Harbs

2 replies

Inspiring
January 12, 2012

I did a bit more digging in the document that is causing the original translation to error.

The object that is causing the problem is called "<pasted graphic>" in the links palette.

Visually it looks like a small ammount of drop shadow on a white background.

Harbs.
Harbs.Correct answer
Legend
January 12, 2012

Sorry, my code had an error:

var documentLinks = app.activeDocument.links.everyItem().filePath;


Harbs

Inspiring
January 12, 2012

Thanks Harbs!

Harbs.
Legend
January 11, 2012

A direct translation would be:

var documentLinks = app.activeDocument.links.everyItem().path;

Harbs

Inspiring
January 11, 2012

Hi Harbs,

Thanks for the reply!

When i try to run the above i get "Object does not support property or method 'path'"?

any ideas?