2 Replies Latest reply on Sep 29, 2009 7:36 PM by dhishok

    apple script to java script...

    dhishok Level 1

      Hi everyone,

       

      As i want to change below apple script code to java script. I have tried upto duplicating the frames with java script and its working fine. But i don't know how to use whose condition in javascript. If it is possible to do whose condition  in java script then i don't want to go for loop. Can anyone look into this and help me out.

       

      -----Apple script-----

       

      set xx to {}
      tell application "Adobe InDesign CS3"
          tell document 1
              repeat with i from 1 to (count of text frame)
                  if class of parent of parent of text frame i is not in master spread then
                      set end of xx to id of text frame i
                  end if
              end repeat
              duplicate (every text frame whose id is in xx)
              delete (every text frame whose id is in xx)
          end tell
      end tell

       

       

      //---Java script---

       

      var doc=app.activeDocument;

      var myFrames=doc.textFrames.everyItem();

      myFrames.duplicate();

       

      //----

       

       

       

      Thanks in advance

       

      Thiyagu

        • 1. Re: apple script to java script...
          Kasyan Servetsky Level 5

          JavaScript doesn't have an equivalent of AppleScript's whose clause. So a JS version of your script might look like this:

           

          var myDoc = app.activeDocument;
          var myFrames=myDoc.textFrames.everyItem().getElements();
          var xx = [];
          for (i = 0; i < myFrames.length; i++) {
              var myFrame = myFrames[i];
              if (myFrame.parent.parent.constructor.name != "MasterSpread") {
                  xx.push(myFrame.id);
              }
          }

           

          for (j = myFrames.length-1; j >= 0; j--) {
              myFrame =  myFrames[j];
              if (IsInArray(myFrame.id, xx)) {
                  var myDup = myFrame.duplicate();
                  myFrame.remove();
              }
          }

           

          function IsInArray(myString, myArray) {
              for (x in myArray) {
                  if (myString == myArray[x]) {
                      return true;
                  }
              }
              return false;
          }

          • 2. Re: apple script to java script...
            dhishok Level 1

            Hi Kasyan,

             

            I have checked with your code its working fine. Thanks for your valuable & great support. I was out of station for past one week. Thats the reason for no reply.

             

            After posted my query in to forums, in the mean time i developed the script. In this script i supposed to use the same approach to unlink frames, by getting frame IDs of the text frames. For time consuming only i expected the equivalent code of JS. For your reference i have posted my script below.

             

            //-----------------

            var doc=app.activeDocument;
            var myArray=new Array();
            var myFrames=doc.textFrames.everyItem().id;
            for(j=0; j<myFrames.length; j++)
                {
                    myArray.push(myFrames[j]);
                }
            doc.textFrames.everyItem().duplicate();
            var myDupFrames=doc.textFrames;
            for (k=0; k<myDupFrames.length; k++)
                {
                for(s=0; s<myArray.length; s++)
                {
                    if (myDupFrames[k].id==myArray[s])
                    {

                      myDupFrames[k].remove();
                      break;
                    }
                 }
            }

            //-----------------

             

            Also i have modified my script  after seen your post. And it is working greatly. Once again i am thanking you.

             

            Regards

            Thiyagu