4 Replies Latest reply on Jun 14, 2016 1:53 AM by natrev

    JS to get the txt filename after being placed.

    eboda_snaf Level 1

      hi there,

      any idea how to get the txt filename being placed by ctrl+D using JS?

       

      Thanks!

        • 1. Re: JS to get the txt filename after being placed.
          karthiks94217840 Level 2

          Try this

           

          Multi file auto place

           

          //**********************

          var myDoc = app.activeDocument, 

          myFiles = File.openDialog("Select files to place...", undefined, true), 

          i, 

          currentPage = myDoc.pages[0], 

          prevFrame, 

          myFrame; 

             

          for (i = 0; i < myFiles.length; i++){ 

          myFrame = addFrame(currentPage); 

          myFile = myFiles[i]; 

          try{ 

            myFrame.place(myFile, false); 

          catch(e){ 

            alert("Unable to place file: "+myFile, "Multi-file auto-place"); 

            continue; 

          while (myFrame.overflows){ 

            currentPage = addPageAfter(currentPage); 

            prevFrame = myFrame; 

            myFrame = addFrame(currentPage); 

            prevFrame.nextTextFrame = myFrame; 

          currentPage = addPageAfter(currentPage); 

          function addFrame(aPage){ 

          var pageMargins = aPage.marginPreferences, 

            aFrame = aPage.textFrames.add(), 

            areFacing = app.activeDocument.documentPreferences.facingPages, 

            myTop = aPage.bounds[0]+pageMargins.top, 

            myBottom = aPage.bounds[2]-pageMargins.bottom, 

            myLeft = aPage.bounds[1]+pageMargins.left, 

            myRight = aPage.bounds[3]-pageMargins.right; 

          //When document.documentPreferences.facingPages == true, 

          //"left" means inside; "right" means outside. 

          if (areFacing && aPage.side == PageSideOptions.LEFT_HAND){ 

             myLeft = aPage.bounds[1]+pageMargins.right; 

             myRight = aPage.bounds[3]-pageMargins.left; 

          aFrame.geometricBounds = [myTop, myLeft, myBottom, myRight]; 

          return aFrame; 

            

          function addPageAfter(aPage){ 

          return myDoc.pages.add(LocationOptions.AFTER, aPage); 

          }

           

          //***************

           

          Thanks

          • 2. Re: JS to get the txt filename after being placed.
            eboda_snaf Level 1

            Thanks for your reply.

            I think you have mistaken my question.

             

            i needed a JS that's able to obtain the actual fileNAME of the .txt that was placed using the default "PLACE" action.

            e.g "123.txt"

            • 3. Re: JS to get the txt filename after being placed.
              Ravindra_KCS Level 1

              Hi Ebo,

                        As text file is placed as textFrame not as linked items. So its actual name can't accessible.

               

              ...Thanks

              Ravindra

              • 4. Re: JS to get the txt filename after being placed.
                natrev Level 3

                Hi

                Make sure you check the preference in as shown below, before you place the text file

                It will store text file as link. Hence you can get the file name from link palette.

                 

                Screen Shot 2016-06-14 at 2.17.24 pm.png