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


      function main(){

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

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



          var fileList =[];

          fileList =GetFilesFromBridge();


              alert("Nenhumas imagens em Bridge!");



          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;




      ////////  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(/\.[^\.]+$/, '');



          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');";



          BridgeTalk.bringToFront ("bridge");

              function GetFilesFromBridge() {

                  function script(){


                      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(); }



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

                   return fileList;