7 Replies Latest reply on Sep 11, 2008 6:25 PM by (xxnu)

    packageForPrint script.

      I'm *trying* to write a javascript and would appreciate any help I can get on this.

      var myDocument = app.activeDocument;
      var myFolder = //the current documents folder;
      var packagePath = //desktop/packages/"the current documents filename minus .indd"

      myDocument.packageForPrint(packagePath, false, true, false, true, true, true, false);

      //close the current doc

      //move mydocument.indd from /desktop/packages/"the current documents filename minus .indd" to myFolder
      //move the contents of /desktop/packages/"the current documents filename minus .indd"/links to myFolder

      Thats more a literal translation of what I want to do.

      so any guidance would be appreciated.

      So far I have only been able to find a couple of references to the PackageForPrint function from the net, is there any reason this isn't included in the InDesign Javascript refernce?
        • 1. Re: packageForPrint script.
          Loic.Aigon Adobe Community Professional
          var docname = myDocument.name;

          var X = //the path to your desktop folder, depends on the system you have.
          //Can be st like "/c/documents and settings.../desktop/packages

          var Y = docname.split(".indd");

          var packagePath = X+"/"+Y;

          At this time you should probably add a checking condition to verify that the folder exists or not. Or your script may fail.
          In case it doesn't exists, the script may create the specified folder.

          You can find a lot of info on Files managing in the ESTK documentation (help)

          var myInddfile = File("/desktop/packages/mydocument.indd").changePath(myFolder);

          //In fact why are you needing this ? The file you created with the package command is the same that you close. Where is the point ?

          Here are a few exercices :-)
          Good luck
          Loic
          • 2. Re: packageForPrint script.
            Level 1
            OK, what I am trying to to is bring all the linked files into the same directory as the indd file, and make sure all the links are putting to the files newly shifted.

            The files need to be in the SAME directory as the INDD file, not a folder called links (in whatever the target directory is).

            while trying to run a few scripts today, InDesign didn't seem to want to copy the links to the same folder as the INDD file.

            which is why I have to copy them to (the desktop) and then back to the job folder.
            • 3. Re: packageForPrint script.
              Loic.Aigon Adobe Community Professional
              Ok, <br />well,<br /><br />var mylinkfolder = Folder(mylinkfolderpath);<br />var mylinkfiles = mylinkfolder.getFiles();<br />for(i=0; i<mylinkfiles.length; i++)<br />{<br />  mylinkfiles[i].changePath(mydocfolderpath);<br />}<br />mylinkfolder.remove(); //Guess you don't need it anymore...<br /><br />you just have to define mylinkfolderpath  & mydocfolderpath<br /><br />Loic
              • 4. Re: packageForPrint script.
                Level 1
                OK so... <br /><br />var myDocument = app.activeDocument;<br />var docname = myDocument.name;<br />var X = "C:/temp";<br />var Y = docname.split(".indd");<br />var packagePath = X+"/"+Y; <br />var myLinkFolder = new Folder(packagePath + "/Links/");<br />var myDocFolder = "C:/test";<br />//var myFolder = Folder.selectDialog("Please select a folder");<br />myDocument.packageForPrint(myLinkFolder, false, true, false, true, true, true, false);<br />var myLinkFiles = myLinkFolder.getFiles();<br />for(i=0; i<myLinkFiles.length; i++) { myLinkFiles[i].changePath(myDocFolder); } myLinkFolder.remove();<br /><br />is popping up this error:<br /><br />Error Number 24:<br />Error String: myLinkFiles[0].changePath is not a function"<br />Line 12<br />Source: for(i=0; i<myLinkFiles.length; i++) { myLinkFiles[i].changePath(myDocFolder); } myLinkFolder.remove();<br /><br />Also how can I define  myDocFolder as the current documents file path?<br /><br />ALSO why is the package folder creating with a , at the end of it.<br />I.E: C:/temp/test,<br /><br />Thanks for your help this far though!!
                • 5. Re: packageForPrint script.
                  Level 1
                  ALLLSSSOO myLinkFolder.remove(); isn't removing the package folder?
                  • 6. Re: packageForPrint script.
                    Loic.Aigon Adobe Community Professional
                    Error String: myLinkFiles[0].changePath is not a function"

                    I don't think the method is false. I suspect rather that is a reference error. Don't ask me why but
                    b var myLinkFolder = new Folder(packagePath + "/Links/");
                    is just a reference.
                    b It did not create the folder.
                    So unless it already exists when you do
                    var myLinkFiles = myLinkFolder.getFiles();
                    you are actually looking into nothing. So as a chain reaction, nothing really works.

                    try this
                    ...
                    var myLinkFolder = new Folder(packagePath + "/Links/");

                    b myLinkFolder.create(); //will create the folder
                    ...

                    if you use this script quite often, you should add the if exists condition :
                    if(folder.exists==false) folder.create();

                    b Regarding to the comma error.
                    My mistake. In fact, split creates two entities.
                    here you have xxxx,"" wher "" is no content.
                    I mean
                    var X = "abcde"; X.split("cd") > ab,e
                    SO we have to restreign the method to the only part we want.
                    ex: X.split("cd")[0] > ab
                    b var Y = docname.split(".indd")[0];

                    b ALLLSSSOO myLinkFolder.remove(); isn't removing the package folder?

                    I don't know how I hav to interprate your alllsssoo but :
                    b this is the same issue as the introduction.
                    myLinkFolder shall not exists so the script has nothing to remove.

                    I hope it helps.

                    Loic
                    • 7. Re: packageForPrint script.
                      Level 1
                      var myDocument = app.activeDocument;<br />var docname = myDocument.name;<br />var packagePath = myDocument.filePath+"/package/"; <br />var myDocFolder = new Folder(myDocument.filePath+"/");<br />var myPackageFolder = new Folder(packagePath);<br />myPackageFolder.create();<br />myDocument.packageForPrint(myPackageFolder, true, true, true, true, true, true, false);<br /><br />var myLinkFolder = new Folder(myPackageFolder+"/Links/");<br />var myLinkFiles = myLinkFolder.getFiles();<br /><br />alert(myLinkFiles);<br /><br />for(i=0; i<myLinkFiles.length; i++) {<br /> var linkfile = new File(myLinkFiles[i]);<br /> linkfile.Move(myDocFolder, true);<br />}<br />myPackageFolder.remove();<br /><br />I get an error with the move function and it doesn't seem to want to delete the folder if it has contents