6 Replies Latest reply on May 6, 2018 10:34 AM by Polycontrast

    Select Bridge thumbnails run custom Photoshop script

    Polycontrast Level 1

      Working with high image volume. Use a photoshop script to create derivative files from the master PSD file in Photoshop. Like to be able to select the PSD files in Bridge and run the Photoshop script from Bridge.  Is there a method or function to select thumbnails in Bridge and to run a Photoshop script?

       

      Environment

      Bridge CC 2018

      Photoshop CC 2018

      OSX High Sierra

        • 1. Re: Select Bridge thumbnails run custom Photoshop script
          SuperMerlin Level 5

          In Bridge use $.evalFile(); to execute your Photoshop script, in your Photoshop script get the selected files.

          function getFilesFromBridge(){
          var fileList =[];
          var bt = new BridgeTalk();
          bt.target = "bridge";
          bt.body = "var F = photoshop.getBridgeFileListForAutomateCommand();F.toSource();";
          bt.onResult = function( inBT ) { fileList = eval( inBT.body ); }
          bt.onError = function( inBT ) { fileList = new Array(); }
          bt.send(8);
          return fileList;
          };
          
          
          • 2. Re: Select Bridge thumbnails run custom Photoshop script
            Polycontrast Level 1

            I have basic scripting knowledge. Is there sample Bridge script which calls a photoshop script after a thumbnail is selected in Bridge?  I have installed my custom Bridge script and can access it through the menu, but the Photoshop script does not execute when run from bridge.

            • 3. Re: Select Bridge thumbnails run custom Photoshop script
              SuperMerlin Level 5

              Once you have selected you files you can use this script to call the Photoshop script.

              N.B. The Photoshop script must get the selected files as in the above example.

              Amend the scriptName variable to your Photoshop script name.

              #target bridge   
                 if( BridgeTalk.appName == "bridge" ) {  
              runjsx = MenuElement.create("command", "Run Photoshop JSX", "at the end of Tools");
              }
              runjsx .onSelect  = function () { 
              function script(){
                  /*amend with your script name*/
              var scriptName = "Your File Name.jsx"; 
              var f = File(app.path + "/presets/scripts/" + scriptName);
              $.evalFile(f);
              }
              var bt = new BridgeTalk; 
              bt.target = "photoshop"; 
              bt.body = " ftn = " + script.toSource() + "; ftn();";
              bt.send(8); 
              };
              
              
              1 person found this helpful
              • 4. Re: Select Bridge thumbnails run custom Photoshop script
                Polycontrast Level 1

                Thank you for your help SuperMerlin, the code does work. I understand the Photoshop script needs to get the selected files from Bridge. I have placed the function getFilesFromBridge() in the Photoshop script. I am not sure where and how call this function in the Photoshop script. For instance the PS script saves a jpg file with folder selection: Where should I put the function call?

                 

                 

                // save to a folder using a dialog box

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

                if (theFolder) {

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

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

                    }

                 

                 

                //close all documents without saving changes to original

                while(documents.length>0){ 

                        documents[documents.length-1].close(SaveOptions.DONOTSAVECHANGES);

                    }

                 

                // jpeg save file options

                var jpgOptions = new JPEGSaveOptions();

                jpgOptions.embedColorProfile = true;

                jpgOptions.alphaChannels = true;

                jpgOptions.layers = true;

                jpgOptions.spotColors = true;

                 

                // get selected files from Bridge

                function getFilesFromBridge(){ 

                    var fileList =[]; 

                    var bt = new BridgeTalk(); 

                    bt.target = "bridge"; 

                    bt.body = "var F = photoshop.getBridgeFileListForAutomateCommand();F.toSource();"; 

                    bt.onResult = function( inBT ) { fileList = eval( inBT.body ); } 

                    bt.onError = function( inBT ) { fileList = new Array(); } 

                    bt.send(8); 

                    return fileList; 

                };

                • 5. Re: Select Bridge thumbnails run custom Photoshop script
                  SuperMerlin Level 5

                  Hope this helps...

                   

                  #target photoshop;
                  app.bringToFront();
                  main();
                  function main(){
                  //get an array of files from Bridge
                  var files = GetFilesFromBridge();
                  //get output folder
                  outputFolder = Folder.selectDialog("Please select Output folder");
                  if(outputFolder == null ) return;
                  //iterate through Bridge files
                  for(var a in files){
                  //open each file in turn
                  app.open(files[a]);
                  //get the filename without extension
                  var Name = files[a].name.replace(/\.[^\.]+$/, '');
                  //create new filename
                  var saveFile = File(outputFolder +"/" +Name + ".jpg");
                  //save file
                  SaveJPEG(saveFile,8);
                  //close document
                  app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 
                  }//end files
                  }
                  //FUNCTIONS
                  function GetFilesFromBridge() {
                      var fileList=[];
                      if ( BridgeTalk.isRunning( "bridge" ) ) {
                          var bt = new BridgeTalk();
                          bt.target = "bridge";
                          bt.body = "var theFiles = photoshop.getBridgeFileListForAutomateCommand();theFiles.toSource();";
                          bt.onResult = function( inBT ) { fileList = eval( inBT.body ); }
                          bt.onError = function( inBT ) { fileList = new Array(); }
                          bt.send(8);
                      }
                      return fileList; 
                  };
                  function SaveJPEG(saveFile, jpegQuality){
                  jpgSaveOptions = new JPEGSaveOptions();
                  jpgSaveOptions.embedColorProfile = true;
                  jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
                  jpgSaveOptions.matte = MatteType.NONE;
                  jpgSaveOptions.quality = jpegQuality;
                  activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
                  };
                  
                  
                  
                  2 people found this helpful
                  • 6. Re: Select Bridge thumbnails run custom Photoshop script
                    Polycontrast Level 1

                    Thank you SuperMerlin the script works great! I appreciate your comments on the script, it makes easy to follow the logic.