1 Reply Latest reply: Nov 8, 2014 3:06 PM by ojodegato RSS

    complicated question: dialog box-batch processing script

    ojodegato Community Member

      I am adapting the working script I found on this forum.

      Script: Open files as layers in Photoshop

      https://forums.adobe.com/thread/1313579

       

      The goal of the adaptation is to include a javascript Folder dialog to set the save folder destination at run time and

      use this folder destination for the remaining script batch processing functions.

       

      Presently, the script loads a Bridge stack as Photoshop layers and saves the layered tiff using the Folder dialog.

      The folder dialog is manifesting every time the script encounters a Bridge stack.

       

      The question is what is the correct script logic to set the destination folder once at run time and keep this destination

      folder for the stack batch processing.

       

      #target bridge

       

      var stacks = app.document.stacks;

      var stackCount = stacks.length;

      for(var s = 0;s<stackCount;s++){

            var stackFiles = getStackFiles( stacks[s] );

            if(stackFiles.length> 1){

                 var bt = new BridgeTalk;

                 bt.target = "photoshop";

                 var myScript = ("var ftn = " + psRemote.toSource() + "; ftn("+stackFiles.toSource()+");");

                 bt.body = myScript;

                 bt.send(5);

            }

      }

      function getStackFiles( stack ){

            var files = new Array();

            for( var f = 0; f<stack.thumbnails.length;f++){

                 files.push(stack.thumbnails[f].spec);

            }

            return files;

      };

      function psRemote(stackFiles){

      app.bringToFront();

      var thisDoc = open(File(stackFiles[0]));

      var Name = decodeURI(app.activeDocument.name).slice(0,-4);

      thisDoc.layers[0].name = decodeURI(Name);

      for(var a = 1;a<stackFiles.length;a++){

          open(File(stackFiles[a]));

          Name = decodeURI(app.activeDocument.name).slice(0,-4);

          activeDocument.activeLayer.duplicate(thisDoc);

          app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

          thisDoc.layers[0].name = Name;

          }

       

      var tifOptions = new TiffSaveOptions();

      tifOptions = new TiffSaveOptions();

      tifOptions.embedColorProfile = true;

      tifOptions.imageCompression = TIFFEncoding.TIFFLZW;

      tifOptions.alphaChannels = false;

      tifOptions.byteOrder = ByteOrder.MACOS;

      tifOptions.layers = true;

       

      var theFolder = Folder.selectDialog ("Select Folder");

      if (theFolder) {

              var myFile = new File( theFolder + "/" + app.activeDocument.name);

              app.activeDocument.saveAs(myFile, tifOptions, true);  

          }

      app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

       

      }