2 Replies Latest reply on May 25, 2010 2:24 PM by John Hawkinson

    How can a script access all link properties?


      I'm really glad to find this pool of expertise out in the cloud. TIA for all replies.


      I'm looking for proper syntax to access the more detailed properties of graphic file links, such as the page# on which they appear and effective PPI. These are visible in the link window, but I cannot find them in the ESTK for CS4 Object Model Viewer. There is are name, filePath, and linkType, which are all very useful and also visible in the link window. But as for the other info I see only a suggestive attribute called "properties" which is itself an object, and I cannot seem to query its contents.


      As I'm very, very new to scripting the cause could be little more than my own ignorance.


      Is there a way to convert and object to strings so I can see how it is built?


      In case anyone is interested, I'm trying to amplify a very helpful little script written three years ago by Steve Wareham:


      // ====== ListLinks ====== \\


      /* This is a JavaScript for InDesign. It will create a new text box on the first page of your document, and list all the links used in your document.

      A dialog box provides options to list the links names, files paths, and file types. Created by Steve Wareham 5/08/2007

      attempts to amplify with addition of Page and Effective PPP by Marc Shargel May 2010 */


      // ----- Dialog Box ------\\

      var myDialog = app.dialogs.add({name:"Link Lister", canCancel:true});






      staticTexts.add({staticLabel:"What link information do you want? "});




      var my1RadioButton = checkboxControls.add({staticLabel:"Names", checkedState:true});

      var my2RadioButton = checkboxControls.add({staticLabel:"Paths"});

      var my3RadioButton = checkboxControls.add({staticLabel:"File type"});

      var my4RadioButton = checkboxControls.add({staticLabel:"Page"});

      var my5RadioButton = checkboxControls.add({staticLabel:"Effective PPI"});

      // extending the dialogue box was easy...






      // ----- End of Dialog Box ----- \\


      //----- Begin ----- \\

      if(myDialog.show() == true){


      var myDocument = app.activeDocument;

      var totalLinks = myDocument.links.length;


      var myNewTextFrame = myDocument.textFrames.add() // Add a text frame to display the list of links

      myNewTextFrame.geometricBounds = [ "0p0", "0p0", "50p5", "50p5"];


      for ( i = 0;  i < totalLinks;  i++ )


      if (my1RadioButton.checkedState == true) {

      myNewTextFrame.contents = ( myNewTextFrame.contents + "File: " + myDocument.links.item(i).name );


      if (my1RadioButton.checkedState == true) {

      myNewTextFrame.contents = ( myNewTextFrame.contents + " Path: " + myDocument.links.item(i).filePath );


      if (my3RadioButton.checkedState == true) {

      myNewTextFrame.contents = ( myNewTextFrame.contents + " Type: " + myDocument.links.item(i).linkType );


      //... but the following lines do not work. I can refer to "myDocument.links.item(i).properties" but it is reported as an object.

      //if (my4RadioButton.checkedState == true) {

      //myNewTextFrame.contents = ( myNewTextFrame.contents + " Page#: " + myDocument.links.item(i).page );


      //if (my5RadioButton.checkedState == true) {

      // myNewTextFrame.contents = ( myNewTextFrame.contents + " PPI: " + myDocument.links.item(i).effectivePPI );


      myNewTextFrame.contents = ( myNewTextFrame.contents + '\r' );





        • 1. Re: How can a script access all link properties?
          John Hawkinson Level 5

          Many of the things you are looking for are not properties of the link, but rather of the image that the link is a child of.


          For instance, if you have a link l, then the effectivePpi is l.parent.effectivePpi.


          Similarly, for the page number, you would take l.parent.parent.parent.name. That's because the link is the child of an image, which is the child of a box (rectangle, polygon, oval, etc.), which is the child of a page, which has a name (which is typically a page number). Note that if you have to deal with links inside of groups, then it becomes more complicated and you can't just blindly asume the box is contained directly by the page.


          The properties object is not very useful most of the time. It is a convenience for letting you set multiple values of its parent object at once. I'm not aware of any use it has for queries/lookups.


          You can, by the way, write your references more succinctly. Instead of myDocument.links.item(i).name just say myDocument.links[i].name.

          • 2. Re: How can a script access all link properties?
            John Hawkinson Level 5
            Is there a way to convert and object to strings so I can see how it is built?


            Whoops, I'd meant to answer this. Sure, you can just loop over the object. For instance, since you were curious about the "properties" member, suppose we wanted to look at the individual members of the properties object of a link.


            Just type in the JavaScript console:

            { var p = app.activeDocument.links[0].properties; for (var i in p) $.writeln(i + "\t"+p[i]); }


            which produces:

            versionState     1986221653
            editingState     1986217301
            linkXmp     [object LinkMetadata]
            index     0
            parent     [object Image]
            edited     false
            name     yeti.png
            needed     true
            status     1852797549
            linkType     Portable Network Graphics (PNG)
            date     Mon May 24 2010 15:36:52 GMT-0400
            size     113083
            filePath     Hermann Zapf:Users:writer:Desktop:yeti.png
            id     209


            You'll note that these are all the same members that the links[0] object itself has. Again, "properties" is just a convenience for setting more than one at once. So compare the output to:

            { var p =  app.activeDocument.links[0]; for (var i in p) $.writeln(i +  "\t"+p[i]); }


            How does that work? Well, the syntax "for (i in p)" calls the for loop once for every member of the Object p, and then we print out the name of each member along with its value.


            (I guess the good JavaScript programmers would encourage you to put {}'s around the $.writeln, and the really anal people would remind you that JavaScript does not have block scope* and therefore you should wrap the whole thing in:

            "function(){ ... }()".

            (*:reference is to Javascript: The Good Parts; Awful Parts, a book (well, chapter thereof) well worth reading.))

            1 person found this helpful