3 Replies Latest reply on Jul 17, 2010 11:48 AM by Muppet Mark-QAl63s

    how to run system command

    bacas_christy

      Hi

       

      Is that possible to run system command in indesign javascript?

       

      Becase i need to run a command in run prompt while script running in .indd file.

       

      Any idea please let me know

        • 1. Re: how to run system command
          Maciej Przepióra Level 2

          There are at least five answers

          1. No, at least not with ExtendScript. It is not possible to ask InDesign to run a command in system prompt/shell. However don't stop reading.
          2. It is possible to mimick this behaviuor. ExtendScript class File contains a method called execute(). You could create a batch file (on Windows) or shell script (on Mac) with the command and then call execute() on coresponding File object. Drawback is that you won't get back output in a form that your script could use.
          3. With InDesign CS5 and Creative Suite SDK you could use AIR API called NativeProcess. However, this is limited to CS5 and requires knowledge of ActionScript and Flex. I haven't tested it, so I'm not sure it works.
          4. If ExtendScript and platform portability (MacOS <=> Windows) is not an issue (i.e. your script will be running only on one platform) you can always use APIs provided by your scripting environment – AppleScript or Microsoft COM.
          5. Whe all alse fails you could use Rorohiko APID plugin, which provides such feature for ExtendScript. Catch up with Rorohiko Chris on this forum, he is the author of the mentioned plugin.

           

          I Hope this is helpful

          • 2. Re: how to run system command
            bacas_christy Level 1

            Hi Maciej,

             

            For time being i m already using the execute() only for generating pdf from ps.

             

            In this case i cant able set job option in distiller.

             

            The problem y i m trying to run system command is i need pass some parameters (ie., job option, mypsFile) through my script.

             

            Is there any other sollutions?

             

            Thank and Regards

            Christy

            • 3. Re: how to run system command
              Muppet Mark-QAl63s Level 4

              Distiller has the option to set up 'watched folders' each of these folders can have its own set of .joboptions applied as a rule. You could either write your postscript file to that location or move it there once written. The other option on the mac OS would be Distiller is scriptable thru AppleScript it only has 3 parameters so you could call that and pass it the strings?

               

              #target indesign
              
              var psFile = new File('~/Desktop/Test Folder/Testing.ps');
              var pdfFile = new File('~/Desktop/Testing.pdf');
              var optsFile = new File('/Library/Application Support/Adobe/Adobe PDF/Settings/Press Quality.joboptions');
              
              distillPS(psFile, pdfFile, optsFile);
              if (pdfFile.exists) alert('Done it…');
              
              function distillPS(sp, dp, opts) {
                   if (!sp instanceof File || !sp.exists) return false;
                   if (!dp instanceof File) return false;
                   if (!opts instanceof File || !opts.exists) return false;
                   // Wants POSIX paths but NOT using '~' home
                   var sourcePath = 'Distill sourcePath "' + sp.fsName + '"';
                   var destPath = ' destinationPath "' + dp.fsName + '"';
                   var settingsPath = ' adobePDFSettingsPath "' + opts.fsName + '"';
                   var allPaths = sourcePath + destPath + settingsPath;
                   // Concat the AppleScript string
                   var pstoPDF = ''
                   + 'tell application "Acrobat Distiller 7.0"' + '\n'
                   + 'activate' + '\n'
                   + allPaths + '\n'
                   + 'quit' + '\n'
                   + 'end tell' + '\n'
                   var result = app.doScript(pstoPDF, 1095978087);
                   return Boolean(result);
              }
              

               

              I added option 4 for the mac. It worked for me with CS2 and Distiller 7. No system check included tho. Just expects 3 File objects 2 of which must exist…