10 Replies Latest reply on Mar 26, 2009 2:14 PM by (John_Kallios)

    JS CS4 Print to postscript

    Level 1
      Part 2 of trying to print to postscript.<br /><br />Current:<br /><br />function mySnippet(){<br />    //<fragment><br />    //Prints the active document using the specified printer preset.<br />    var myDocument = app.documents.item(0);<br />    myDocument.print(true, app.printerPresets.item("ps"));<br />     var printFile = "/Users/john/Desktop/PS_Hotfolder/In/" + myDocument.name;<br />     if(printFile.indexOf(".indd")!=-1){<br />          var myRegularExpression = /.indd/gi<br />          printFile = printFile.replace(myRegularExpression, ".ps");<br />     }<br />     //alert(printFile);<br /><br />I have verified the preset is activated correctly. With the alert, it has returned the file name I am after.<br /><br />Where I'm stuck: The next window where to save the postscript file fails for me. No postscript is created nor does it enter the name in the save dialogue for me.<br /><br />Question: What is the code line to call upon the save dialogue so I may enter the save name?<br /><br />Thanks in advance
        • 1. Re: JS CS4 Print to postscript
          Peter Kahrel Adobe Community Professional & MVP
          John,

          For me this works fine:
          >myDocument.print(true, app.printerPresets.item("ps"))

          Running this line shows the Print then the Print to File dialog, the same that you get when you print from the interface. You can also use this:
          >myDocument.print(false, app.printerPresets.item("ps"))

          Now you get just a small Print to File dialog in which you can enter the name of the file. Maybe give that one a try and see what happens. If you still don't see the dialog you expect, do you see any at all? Could it be that you disabled dialogs using some userInteraction setting? To rule that out, run this one-liner:
          >app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

          and try again.

          As to the file name you construct for the PS file, there's no point doing that because you can't use it in the script. As far as I can see, you have to enter the file name manually in the dialog. This is unlike exporting to EPS, PDF, etc., where you can say something like "export myDoc to PDF using filename X and preset Y". In other words, you can't say "print myDoc as PS using filename X and preset Y". You have to go through the dialog, and you have to type the name.

          Hope this helps.

          Peter
          • 2. Re: JS CS4 Print to postscript
            Kasyan Servetsky Level 5
            >As to the file name you construct for the PS file, there's no point doing that because you can't use it in the script... In other words, you can't say "print myDoc as PS using filename X and preset Y". You have to go through the dialog, and you have to type the name.

            You can use PrintPreference's printFile property to set the name of the PS-file and you can use activePrinterPreset to choose a printer preset in script. I do it in my script that exports each page to a separate PS-file and names each file in the following form:
            Page number + "_Magazine name_" + Issue number + ".ps"
            e.g. 012_business_843.ps
            http://www.kasyan.ho.com.ua/downloads/PrintEachPageAsPs%20v3.6.zip
            • 3. Re: JS CS4 Print to postscript
              Level 1
              Hello,

              When I turn the print line to true, the print dialog appears and correctly targets my preset. Clicking save brings up the second save dialog.

              When it is false, the second dialog does not appear.

              I will try the script to ensure no user action was turned off.

              The scripting guide mentions when setting print preferences:

              //If the printer property is set to Printer.postScript file, then the printFile property contains the file path to the output file.
              //printFile = "/c/test.ps"

              This led me believe that I could write to the 2nd dialog. However, if I cannot, I will initiate phase 2. While sounding official, it just means I will convert my department from distilling ps to pdf to exporting to pdf.

              I estimated 10 more jobs prepped per day with printing to postscript, I should be able to get 15 more with exporting.

              You will be seeing a new questing, in a new topic, soon after I bang my head against the wall:

              "How to get the full document path of the file and export the pdf one level up and back into anther sub folder. Plus, gleaming what the other subfolder's name is."

              Example:

              File name: "jobnumber"+"other text"
              ~document path/working
              move up path to
              ~document path
              move into subfolder
              ~document path/"jobnumber"+"pdf"

              and save the file with the document name.

              I'll need to throw in an if statement to check if the file ever was saved to begin with.

              Now I'm thinking out loud. Please forgive me.
              • 4. Re: JS CS4 Print to postscript
                Level 1
                Thank you Kasyan,

                I will be able to try later this morning. First order of business is to get my son off to school.

                Cheers.
                • 5. Re: JS CS4 Print to postscript
                  Kasyan Servetsky Level 5
                  Hi John,

                  I'm not sure if this is exactly what you want. I assume that you want to save a ps-file to 'PS_Files' folder which is one level up relative to the folder where the current InDesign's file resides. If such folder doesn't exist it will be created after confirmation.

                  Kasyan

                  var myDoc = app.activeDocument;
                  
                  var myPrintPrefs = myDoc.printPreferences;

                  if (app.printerPresets.item("ps") == null) {
                     alert("Printer preset \"ps\" is not installed.");
                     exit();
                  }
                  else {
                     myPrintPrefs.activePrinterPreset = app.printerPresets.item("ps"); 
                  }

                  var myDocPath = myDoc.filePath;
                  var myFileName = myDoc.name.replace(/\.indd$/i, "") + ".ps";
                  var myPsFolder = new Folder(myDocPath.parent.fsName + "/PS_Files");

                  if (!myPsFolder.exists) {
                     var myConfirm = confirm("Folder \"PS_Files\" doesn't exists. Do you wan to create it?");
                     if (myConfirm) {
                        myPsFolder.create();
                     }
                     else {
                        exit();
                     }
                  }

                  var myFile = new File(myPsFolder + "/" + myFileName);
                  myPrintPrefs.printFile = myFile;
                  myDoc.print(false);
                  alert("All done!");
                  • 6. Re: JS CS4 Print to postscript
                    Peter Kahrel Adobe Community Professional & MVP
                    >You can use PrintPreference's printFile property ...

                    Well, that shows I've not used that before.

                    Peter
                    • 7. Re: JS CS4 Print to postscript
                      Level 1
                      Thank you Peter and Kasyan,

                      You are both a big help. Thank you very much Kasyan for the code. You do know I will take credit at my work? Actually, I am very big on given credit where due. :)

                      For closure, I respond back when I have a completed script.

                      If you could not guess, I'm a newbie uninitiated. <-- Dave Saunders labeled me
                      • 8. Re: JS CS4 Print to postscript
                        Level 1
                        Semi-closure: Thanks again Kasyan for the script. I'm printing PS to the folder I want to.

                        Follow up question for all.

                        On a Mac, what is the string of text to point to the desktop regardless of the username logged in?

                        Thanks,

                        John
                        • 9. Re: JS CS4 Print to postscript
                          Kasyan Servetsky Level 5
                          var myFolder = Folder ("~/Desktop");
                          

                          both for Mac & Pc
                          • 10. Re: JS CS4 Print to postscript
                            Level 1
                            Thanks again!