0 Replies Latest reply on Jun 22, 2012 7:11 AM by Pedro Cortez Marques

    Passing external string to author XMP when opening CR2

    Pedro Cortez Marques Level 3

      Sorry I can't find my last year post. I have this code suggested by Paul Riggott or Michael L Hale (...?) that is helping me a lot. But I must improve it a bit more.

       

      I added an external variable (a text file that contains a variable) but now I must pass that string to each of the several CR2 XMP author .

       

      This the code (incompleted):

      it reads all the present CR2 files on Bridge on the manual order and open them on ACRaw

       

       

       

      ////////////////////////////////

      #target photoshop

      main();

      function main(){

          if (!BridgeTalk.isRunning("bridge")){

              alert("Só funciona se houver algumas imagens CR2 com o Bridge aberto!");

              return;

          }

          var fileList =[];

          fileList =GetFilesFromBridge();

          if(!fileList.length){

              alert("Nenhumas imagens em Bridge!");

              return;

          }

          var Path = Folder(fileList[0].path);

          var name = Folder(fileList[0].path).name;

          var newName=[];

          for(var a in fileList){

              var nname = fileList[a].name;

              newName.push(nname);

              fileList[a].rename(newName[a]);

          }

      ////////  I have a folder named upload on Desktop (PC) with a text file:

          var uploadFolder =  Folder("~/Desktop/upload");  

          var fileEditor = File(uploadFolder + '/edita.txt');

          if (fileEditor.open('r')) {

              var ler = fileEditor.read();

              var keyList = [];

              keyList[0] = ler.replace(/\.[^\.]+$/, '');

              fileEditor.close();

          }

          var bt = new BridgeTalk();

          bt.target = "bridge";

          bt.body ="var d=app.document; d.deselectAll(); var f=d.getSelection('cr2'); for(var a in f){d.select(f[a])} d.chooseMenuItem('OpenInCameraRaw');";

          bt.send(8);

          bt.pump();

          BridgeTalk.bringToFront ("bridge");

              function GetFilesFromBridge() {

                  function script(){

                      app.document.deselectAll();

                      var fL = app.document.getSelection('cr2');

                      var tF=[];

                      for(var a in fL){

                          if(fL[a].type =='file'){

                              tF.push(new File(encodeURI(fL[a].spec.fsName)));

       

                          }

                      }

                      return tF.toSource();

                  }

                   var fileList;

                  var bt = new BridgeTalk();

                  bt.target = "bridge";

                  bt.body = "var ftn = " + script.toSource() + "; ftn();";

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

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

                  bt.send(8);

                  bt.pump();

                   if ( undefined == fileList ) fileList = new Array();

                   return fileList;

              }

      }

       

      ///////////////////////////