9 Replies Latest reply on Jun 20, 2015 12:35 AM by Philip Cord

    I want to know that how to use 'Bridge Talk'.

    YaoyongYu Level 1
      var bt = new BridgeTalk;      bt.target = "photoshop";      var myScript = WIN.toString() ;      bt.body = myScript;      bt.send();    function WIN(){ var isDone, win, windowResource; isDone = false; windowResource = "palette{\ orientation: 'column', \ alignChildren: ['fill', 'top'],  \ preferredSize:[300, 130], \ text: 'ScriptUI Window - palette',  \ margins:15,  \ frameLocation:[1200,-10],\    }" win = new Window(windowResource); win.show(); app.bringToFront() }

      JJMack 

        • 1. Re: I want to know that how to use 'Bridge Talk'.
          Philip Cord Level 4
          //New Bridgetalk
          var bt = new BridgeTalk();
          //Target application
          bt.target = "bridge";
          //Script to execute on target application
          bt.body = /*script to execute*/;
          //Results  if anything is to be returned
          bt.onResult = function( inBT ) { result = eval( inBT.body ); }
          //If anything goes wrong, error message
          bt.onError = function( inBT ) {alert(inBT.body); }
          //Send the command with a timeout in seconds
          bt.send(8); 
          
          
          
          • 2. Re: I want to know that how to use 'Bridge Talk'.
            YaoyongYu Level 1

            thank u.  .i think it's more better if you give me a sample

            • 3. Re: I want to know that how to use 'Bridge Talk'.
              Philip Cord Level 4

              Here is an example of getting a list of selected files From Bridge any Folders are ignored.

              alert(getSelectedFilesFromBridge().join('\n'));
              
              function getSelectedFilesFromBridge(){
              if (!BridgeTalk.isRunning("bridge")) {
              BridgeTalk.launch("bridge");
              var err = ["Bridge was not running, please run this script again\n Bridge will now be started."];
              return err;
              }
              fileList = new Array();
              var bt = new BridgeTalk();
              bt.target = "bridge";
              bt.body = "var f = " + Script.toSource() + "; f();";
              bt.onResult = function( inBT ) { fileList =eval( inBT.body );}
              bt.onError = function( inBT ) { alert(eval(inBT.body)); }
              bt.send(8);
              return fileList;
              };
              
              function Script(){
              var sels = app.document.selections;
              var Files=[];
              if(!sels.length) Files.push("No Files Selected");
              for(var z =0; z < sels.length;z++){
              if(sels[z].spec instanceof File) {
              Files.push(sels[z].spec);
                  }
              }
              return Files.toSource();
              };
              
              
              
              
              • 4. Re: I want to know that how to use 'Bridge Talk'.
                YaoyongYu Level 1

                thank u very very much, my english is not good,I am studying now

                • 5. Re: I want to know that how to use 'Bridge Talk'.
                  YaoyongYu Level 1
                  1. function WinObject() {
                  2.   // Long resource String for 'palette' Window
                  3.   var windowResource ="dialog{text:'Script Interface',bounds:[100,100,400,170],button0:Button{bounds:[30,10,130,30] , text:'选择已选图层' },button1:Button{bounds:[160,10,260,30] , text:'移动到当前' },panel0:Panel{bounds:[0,40,300,70] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true}}};"
                  4. // 窗口文件必须为palette ,不能出现反斜线'\'
                  5.   var win = new Window(windowResource);
                  6.   win.botton0.onClick = function() { win.close() };
                  7.   // 必须要有回调的值
                  8.   win.show();
                  9. };
                  10. var message = WinObject.toString();
                  11. message += "\nnew WinObject();"
                  12. var bt = new BridgeTalk();
                  13. bt.target = "photoshop";
                  14. bt.body = message;
                  15. bt.send();

                   

                  Why can't this jsx pop up a window?

                  • 6. Re: I want to know that how to use 'Bridge Talk'.
                    DBarranca Level 4

                    Typo on line 6 (should be win.button0).

                    Regards,

                     

                    Davide Barranca

                    ---

                    www.davidebarranca.com

                    www.cs-extensions.com

                    • 7. Re: I want to know that how to use 'Bridge Talk'.
                      Philip Cord Level 4

                      There were a few errors in your code:

                      win.botton0.onClick should be win.button1.onClick

                      The var windowResource line needed a ; at the end.

                      Comments MUST be /* comment */

                      Comments using // will stop the script working.

                       

                      function WinObject() {
                        /* Long resource String for 'palette' Window */
                        var windowResource ="dialog{text:'Script Interface',bounds:[100,100,400,170],button0:Button{bounds:[30,10,130,30] , text:'选择已选图层' },button1:Button{bounds:[160,10,260,30] , text:'移动到当前' },panel0:Panel{bounds:[0,40,300,70] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true}}};";
                      /* 窗口文件必须为palette ,不能出现反斜线'\' */
                        var win = new Window(windowResource);
                        win.button1.onClick = function() { win.close() };
                        /*  必须要有回调的值 */
                        win.show();
                      };

                       

                      var message = "var Win =" + WinObject.toSource() + "; Win();";
                      var bt = new BridgeTalk();
                      bt.target = "photoshop";
                      bt.body = message;
                      bt.send();
                      • 8. Re: I want to know that how to use 'Bridge Talk'.
                        YaoyongYu Level 1
                        function WinObject() {
                          /* 注释的文字不能由双斜线开始 */
                            /*只有创建PALETTE才可以支持后台*/
                          var windowResource ="palette{text:'Script Interface',bounds:[100,100,400,170],button0:Button{bounds:[30,10,130,30] , text:'选择已选图层' },button1:Button{bounds:[160,10,260,30] , text:'移动到当前' },panel0:Panel{bounds:[0,40,300,70] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true}}};";
                        /* 窗口声明里不能出现反斜线'\' */
                          var win = new Window(windowResource);
                          win.button0.onClick = function() { win.close()};
                            var laysIDX = getSelectedLayersIdx();
                            win.button1.onClick = function() {alert(laysIDX[0]);};
                          /*  必须要有回调的值 */
                        win.show();
                        };
                        
                        /*There were a few errors in your code:
                        win.botton0.onClick should be win.button1.onClick
                        The var windowResource line needed a ; at    the end.
                        Comments using // will stop the script working.*/
                        
                        
                        var message = WinObject.toString();
                        message += "\nnew WinObject();"
                        var bt = new BridgeTalk();
                        bt.target = "photoshop";
                        bt.body = message;
                        bt.send();
                        
                        
                        function getSelectedLayersIdx(){
                              var selectedLayers = new Array;
                              var ref = new ActionReference();
                              ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
                              var desc = executeActionGet(ref);
                              if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
                                desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
                                  var c = desc.count
                                  var selectedLayers = new Array();
                                  for(var i=0;i<c;i++){
                                    try{
                                      activeDocument.backgroundLayer;
                                      selectedLayers.push(  desc.getReference( i ).getIndex() );
                                    }catch(e){
                                      selectedLayers.push(  desc.getReference( i ).getIndex()+1 );
                                    }
                                  }
                              }else{
                                var ref = new ActionReference();
                                ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
                                ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
                                try{
                                    activeDocument.backgroundLayer;
                                    selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
                                }catch(e){
                                    selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
                                }
                            var vis = app.activeDocument.activeLayer.visible;
                                if(vis == true) app.activeDocument.activeLayer.visible = false;
                                var desc9 = new ActionDescriptor();
                            var list9 = new ActionList();
                            var ref9 = new ActionReference();
                            ref9.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
                            list9.putReference( ref9 );
                            desc9.putList( charIDToTypeID('null'), list9 );
                            executeAction( charIDToTypeID('Shw '), desc9, DialogModes.NO );
                            if(app.activeDocument.activeLayer.visible == false) selectedLayers.shift();
                                app.activeDocument.activeLayer.visible = vis;
                              }
                              return selectedLayers;
                        };
                        
                        
                        

                         

                        Davide Barranca Philip Cord  Thank U,  I got it ,The key lies in "Comments MUST be /* comment */".  But ,when I  Call a subroutine, it can't work

                        • 9. Re: I want to know that how to use 'Bridge Talk'.
                          Philip Cord Level 4

                          That is because you did not send the sub routine to Photoshop.

                           

                          function WinObject() { 
                            /* 注释的文字不能由双斜线开始 */ 
                              /*只有创建PALETTE才可以支持后台*/ 
                            var windowResource ="palette{text:'Script Interface',bounds:[100,100,400,170],button0:Button{bounds:[30,10,130,30] , text:'选择已选图层' },button1:Button{bounds:[160,10,260,30] , text:'移动到当前' },panel0:Panel{bounds:[0,40,300,70] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true}}};"; 
                          /* 窗口声明里不能出现反斜线'\' */ 
                            var win = new Window(windowResource); 
                            win.button0.onClick = function() { win.close()}; 
                              var laysIDX = getSelectedLayersIdx(); 
                              win.button1.onClick = function() {alert(laysIDX[0]);}; 
                            /*  必须要有回调的值 */ 
                          win.show(); 
                              function getSelectedLayersIdx(){ 
                                var selectedLayers = new Array; 
                                var ref = new ActionReference(); 
                                ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                                var desc = executeActionGet(ref); 
                                if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){ 
                                  desc = desc.getList( stringIDToTypeID( 'targetLayers' )); 
                                    var c = desc.count 
                                    var selectedLayers = new Array(); 
                                    for(var i=0;i<c;i++){ 
                                      try{ 
                                        activeDocument.backgroundLayer; 
                                        selectedLayers.push(  desc.getReference( i ).getIndex() ); 
                                      }catch(e){ 
                                        selectedLayers.push(  desc.getReference( i ).getIndex()+1 ); 
                                     
                                   
                                }else{ 
                                  var ref = new ActionReference(); 
                                  ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" )); 
                                  ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                                  try{ 
                                      activeDocument.backgroundLayer; 
                                      selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1); 
                                  }catch(e){ 
                                      selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))); 
                                 
                              var vis = app.activeDocument.activeLayer.visible; 
                                  if(vis == true) app.activeDocument.activeLayer.visible = false; 
                                  var desc9 = new ActionDescriptor(); 
                              var list9 = new ActionList(); 
                              var ref9 = new ActionReference(); 
                              ref9.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') ); 
                              list9.putReference( ref9 ); 
                              desc9.putList( charIDToTypeID('null'), list9 ); 
                              executeAction( charIDToTypeID('Shw '), desc9, DialogModes.NO ); 
                              if(app.activeDocument.activeLayer.visible == false) selectedLayers.shift(); 
                                  app.activeDocument.activeLayer.visible = vis; 
                               
                                return selectedLayers; 
                          }; 
                          }; 
                          /*There were a few errors in your code:
                          win.botton0.onClick should be win.button1.onClick
                          The var windowResource line needed a ; atthe end.
                          Comments using // will stop the script working.*/ 
                          var message = WinObject.toString(); 
                          message += "\nnew WinObject();" 
                          var bt = new BridgeTalk(); 
                          bt.target = "photoshop"; 
                          bt.body = message; 
                          bt.send();