23 Replies Latest reply: Jun 30, 2014 1:10 PM by cdblach RSS

    copy filename to iptc description

    1ewis Community Member

      Hello,

      I need to create a process of copying the filename of a tiff to the description in that same file's iptc. Ideally i'd like to be able to drop the script in to an Apple Automator process, but that would be a luxury. There's also an extra catch: i need the script to replace "=" with ":" and to add a prefix, for example "CMS:"

       

      Here's an example:

       

      input

       

      filename: 8737=6.tif

      description:

       

      output

       

      filename: 8737=6.tif

      description: CMS:8737:6

       

      It seems a faily basic process but i don't know where to start with this scripting business... Any help or advise would be much appreciated! Perhaps you know of a really similar one that i can modify??

       

      Lewis

        • 1. Re: copy filename to iptc description
          Paul Riggott Community Member

          This should do selected documents...

          #target bridge   
             if( BridgeTalk.appName == "bridge" ) {  
          addFileName = MenuElement.create("command", "Add FileName to Description", "at the end of Thumbnail");
          }
          addFileName.onSelect = function () { 
             addFileNameToDescription();
             }
          function addFileNameToDescription(){
          var Prefix = "CMS:";
          var sels = app.document.selections; 
            for (var i = 0; i < sels.length; i++){ 
          var md = sels[i].synchronousMetadata; 
              md.namespace = "http://purl.org/dc/elements/1.1/"; 
              var Name = decodeURI(sels[i].name).replace(/\.[^\.]+$/, '');
              Name = Prefix + Name.replace(/\=/g,':');
              md.description = Name; 
            } 
          }
          
          • 2. Re: copy filename to iptc description
            Paul Riggott Community Member

            Yet another version..

            #target bridge   
               if( BridgeTalk.appName == "bridge" ) {  
            FileNameToDesc = MenuElement.create("command", "Add FileName to Description", "at the end of Thumbnail");
            }
            FileNameToDesc.onSelect = function () { 
               updateFileName();
               }
                  
            function updateFileName(){
             loadXMPLib();
            var Prefix = "CMS:";
            var sels = app.document.selections; 
            for(var a in sels){
            var thumb = new Thumbnail(sels[a]); 
               if(thumb.hasMetadata){ 
                  var selectedFile = thumb.spec;    
                  var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);       
                  var myXmp = myXmpFile.getXMP();    
                  var Name = decodeURI(sels[a].name).replace(/\.[^\.]+$/, '');
                    Name = Prefix + Name.replace(/\=/g,':');
                  myXmp.deleteProperty(XMPConst.NS_DC, "description"); 
                  myXmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default",Name ); 
                  if (myXmpFile.canPutXMP(myXmp)) { 
                myXmpFile.putXMP(myXmp);
                     myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY); 
                     } 
                  } 
            }
            unloadXMPLib();
            }
            function loadXMPLib(){
            if (ExternalObject.AdobeXMPScript == undefined) {
                ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
             }
            }
            function unloadXMPLib(){ 
               if( ExternalObject.AdobeXMPScript ) { 
                  try{ 
                     ExternalObject.AdobeXMPScript.unload(); 
                     ExternalObject.AdobeXMPScript = undefined; 
                  }catch (e){ } 
               } 
            }
            
            • 3. Re: copy filename to iptc description
              1ewis Community Member

              Brilliant, thanks Paul!

              The first one reported an error, but the second works perfectly.

              Lewis

              • 4. Re: copy filename to iptc description
                Beth Coller Community Member

                Hi,

                 

                I am looking to do this same thing. I don't want to change anything in the file name, however. Just want to copy the filename to the iptc description. I don't know anything about scripting. Can you tell me in layman's terms what I need to do?

                 

                Thanks!

                • 5. Re: copy filename to iptc description
                  Muppet Mark Community Member

                  Beth, I just made you a quick edit to Paul's Script… It should now just put the file name in the IPTC… As is it is with the extension too is that right? The script…

                   

                  #target bridge
                  
                  if( BridgeTalk.appName == "bridge" ) {
                       
                       FileNameToDesc = MenuElement.create("command", "Add FileName to Description", "at the end of Thumbnail");
                  };
                  
                  FileNameToDesc.onSelect = function () {
                       
                     updateFileName();
                        
                  };
                        
                  function updateFileName() {
                       
                       loadXMPLib();
                       
                       var sels = app.document.selections;
                       
                       for ( a in sels ) {
                            
                            var thumb = new Thumbnail( sels[a] );
                            
                            if ( thumb.hasMetadata ) {
                                 
                                 var selectedFile = thumb.spec;
                                 
                                 var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE );
                                 
                                 var myXmp = myXmpFile.getXMP();
                                 
                                 var Name = decodeURI( sels[a].name );
                                 
                                 myXmp.deleteProperty( XMPConst.NS_DC, "description" );
                                 
                                 myXmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", Name );
                                 
                                 if ( myXmpFile.canPutXMP( myXmp ) ) {
                                      
                                      myXmpFile.putXMP( myXmp );
                                      
                                      myXmpFile.closeFile( XMPConst.CLOSE_UPDATE_SAFELY );
                                      
                                 } 
                            } 
                       }
                  
                       unloadXMPLib();
                       
                  };
                  
                  function loadXMPLib() {
                       
                       if ( ExternalObject.AdobeXMPScript == undefined ) {
                            
                            ExternalObject.AdobeXMPScript = new ExternalObject( "lib:AdobeXMPScript" );
                            
                       }
                  };
                  
                  function unloadXMPLib() {
                       
                       if( ExternalObject.AdobeXMPScript ) {
                            
                            try {
                                 
                                 ExternalObject.AdobeXMPScript.unload();
                                 
                                 ExternalObject.AdobeXMPScript = undefined;
                                 
                            } catch (e) { }
                       } 
                  };
                  

                   

                  Now to use this there are a couple of things to do.

                   

                  First you need to find where the Adobe 'ExtendScript Toolkit' app is located on your machine? Im on a mac so its down in 'Utilites' folder. If you open that you can cut and paste the above code. Then save it giving it a name and the file extension '.jsx' you can then press the play/run arrow up at the top menu… In Bridge you select the files that you want to do this too. Then use the control key and pick the bottom option…

                  • 6. Re: copy filename to iptc description
                    Paul Riggott Community Member

                    Open ExtendScript Toolkit and paste the following code into the new window.

                    This utility can be found in the relevant folder:-
                    PC: C:\Program Files\Adobe\Adobe Utilities
                    MAC: <hard drive>/Applications/Utilities/Adobe Utilities

                    The script will then be saved to :

                    Open Bridge

                    Edit - Preferences - Startup Scripts

                    At the bottom click the "Reveal Button" this will open the folder where the script should be saved.

                     

                    Close and restart Bridge.

                    Accept the new script.

                     

                    To Use :-

                    Select your documents

                    Mouse right mouse click menu and select  "Add FileName to Description"

                     

                    #target bridge   
                       if( BridgeTalk.appName == "bridge" ) {  
                    FileNameToDesc = MenuElement.create("command", "Add FileName to Description", "at the end of Thumbnail");
                    }
                    FileNameToDesc.onSelect = function () { 
                       updateFileName();
                       }
                          
                    function updateFileName(){
                     loadXMPLib();
                    var sels = app.document.selections; 
                    for(var a in sels){
                    var thumb = new Thumbnail(sels[a]); 
                       if(thumb.hasMetadata){ 
                          var selectedFile = thumb.spec;    
                          var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);       
                          var myXmp = myXmpFile.getXMP();    
                          var Name = decodeURI(sels[a].name).replace(/\.[^\.]+$/, '');
                          myXmp.deleteProperty(XMPConst.NS_DC, "description"); 
                          myXmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default",Name ); 
                          if (myXmpFile.canPutXMP(myXmp)) { 
                        myXmpFile.putXMP(myXmp);
                             myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY); 
                             } 
                          } 
                    }
                    unloadXMPLib();
                    }
                    function loadXMPLib(){
                    if (ExternalObject.AdobeXMPScript == undefined) {
                        ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
                     }
                    }
                    function unloadXMPLib(){ 
                       if( ExternalObject.AdobeXMPScript ) { 
                          try{ 
                             ExternalObject.AdobeXMPScript.unload(); 
                             ExternalObject.AdobeXMPScript = undefined; 
                          }catch (e){ } 
                       } 
                    }
                    

                     

                     

                    • 7. Re: copy filename to iptc description
                      Muppet Mark Community Member

                      And as if by magic the shopkeeper appeared…

                      • 8. Re: copy filename to iptc description
                        Paul Riggott Community Member

                        Hi Mark, disaster here my wonderful laptop has died and I'm having to use the dreaded ghostly coloured laptop with an apple on it! I get a new laptop tomorrow though

                        • 9. Re: copy filename to iptc description
                          Beth Coller Community Member

                          Hi Paul and Mark,

                           

                          Thanks so much for you replies. Neither is quite working for me yet. I was able to open extendscript tool. I saved to adobe scripts as that is the default. The files show up in the extend script app but I'm not sure how to get them into Bridge. When I click the reveal button in the start up scripts utility nothing happens

                           

                          Thanks for your help!!

                          • 10. Re: copy filename to iptc description
                            Paul Riggott Community Member

                            When you click the reveal button it should open a new Finder window on a Mac or Explorer window on a PC, I haven't known this to fail before.

                            • 11. Re: copy filename to iptc description
                              Muppet Mark Community Member

                              I knew there had to be some reason behind me beating you to a reply… It's not often I get the chance… although Im getting further in the % I get done before you beat me… You know you secretly loves the Apple… What tempted Eve n all that… If you can't find anything on it just use spotlight… Do you know where that is? Does the new one come with Windoz 7 because that was my idea… And Im not great on ideas… Im now having to run a second monitor on the imac with CS5 bloody palettes eat loads of desktop… ESTK is now on the second monitor so I can see what Im doing wrong…

                              • 12. Re: copy filename to iptc description
                                Beth Coller Community Member

                                I figured it out and it works perfectly!

                                 

                                Thanks again!!!

                                • 13. Re: copy filename to iptc description
                                  Paul Riggott Community Member

                                  Glad it worked for you Beth!

                                   

                                  Mark, yes I know where spotlight are, have two of them on the front of my car!

                                  • 14. Re: copy filename to iptc description
                                    DonJohnston Community Member

                                    Hi Paul

                                     

                                    I too am an absolute newbie on this topic but it appears to be right up my alley as a solution for automating a lengthy repetitive task I face.

                                     

                                    Would it be possible for you to modify and post your script so that it enables the filename in the Bridge window to be copied to the Document Title field in IPTC.

                                     

                                    Many thanks

                                     

                                    Don

                                    • 15. Re: copy filename to iptc description
                                      Paul Riggott Community Member

                                      No problem, here you are...

                                       

                                      #target bridge   
                                         if( BridgeTalk.appName == "bridge" ) {  
                                      FileNameToDesc = MenuElement.create("command", "Add FileName to Title", "at the end of Thumbnail");
                                      }
                                      FileNameToDesc.onSelect = function () { 
                                         updateFileName();
                                         }
                                            
                                      function updateFileName(){
                                       loadXMPLib();
                                      var sels = app.document.selections; 
                                      for(var a in sels){
                                      var thumb = new Thumbnail(sels[a]); 
                                         if(thumb.hasMetadata){ 
                                            var selectedFile = thumb.spec;    
                                            var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);       
                                            var myXmp = myXmpFile.getXMP();    
                                            var Name = decodeURI(sels[a].name).replace(/\.[^\.]+$/, '');
                                            myXmp.deleteProperty(XMPConst.NS_DC, "title");
                                              myXmp.appendArrayItem(XMPConst.NS_DC, "title", Name, 0, XMPConst.ALIAS_TO_ALT_TEXT);
                                              myXmp.setQualifier(XMPConst.NS_DC, "title[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default");
                                            if (myXmpFile.canPutXMP(myXmp)) { 
                                          myXmpFile.putXMP(myXmp);
                                               myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY); 
                                               } 
                                            } 
                                      }
                                      unloadXMPLib();
                                      }
                                      function loadXMPLib(){
                                      if (ExternalObject.AdobeXMPScript == undefined) {
                                          ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
                                       }
                                      }
                                      function unloadXMPLib(){ 
                                         if( ExternalObject.AdobeXMPScript ) { 
                                            try{ 
                                               ExternalObject.AdobeXMPScript.unload(); 
                                               ExternalObject.AdobeXMPScript = undefined; 
                                            }catch (e){ } 
                                         } 
                                      }
                                      
                                      • 16. Re: copy filename to iptc description
                                        DonJohnston Community Member

                                        Wow Paul, thanks a ton for sharing. It works great! This saves so much time,  and eliminates cut and paste mistakes.

                                         

                                        I am very grateful!

                                         

                                        Don

                                        • 17. Re: copy filename to iptc description
                                          Pedro Marques Community Member

                                          All scripts activated in bridge script folder are not beeing activated in windows7.

                                          I want this so bad, but I only manage to deal with bridge scripting capabilities from spripting photoshop (BridgeTalk) or from ExtendScript toolkit.

                                           

                                          I can't figure what is blocking bridge to manage scripts.

                                          I am a windows7 system administrator.

                                          • 18. Re: copy filename to iptc description
                                            AndrewUSMC Community Member

                                            How do I change the script from Description to Document Title. I've tried a couple of things, name changes and what not, and I can't get it to work for me. Otherwise, the script you provided works great. I just need it to add to the Document Title, not the Description. Thanks for your help.

                                             

                                            • 19. Re: copy filename to iptc description
                                              Paul Riggott Community Member

                                              This copy the filename the the title field..

                                               

                                               

                                              #target bridge   
                                                 if( BridgeTalk.appName == "bridge" ) {  
                                              FT = MenuElement.create("command", "Add FileName to Title", "at the end of Tools");
                                              }
                                              FT.onSelect = function () { 
                                                 AddFilenameToTitle();
                                                 }
                                              function AddFilenameToTitle(){
                                              var thumbs = app.document.selections; 
                                              if(!thumbs.length) return;
                                              if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
                                              for(var a in thumbs){
                                              var selectedFile = thumbs[a].spec;    
                                              var Title = decodeURI(selectedFile.name).replace(/\.[^\.]+$/, '')
                                                    var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE); 
                                                var myXmp = myXmpFile.getXMP();
                                                      myXmp.deleteProperty(XMPConst.NS_DC, "title");
                                                      myXmp.appendArrayItem(XMPConst.NS_DC, "title", Title, 0, XMPConst.ALIAS_TO_ALT_TEXT);
                                                      myXmp.setQualifier(XMPConst.NS_DC, "title[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default");
                                                      if (myXmpFile.canPutXMP(myXmp)) { 
                                                      myXmpFile.putXMP(myXmp);
                                                       myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY); 
                                                       } 
                                                  }
                                              }
                                              
                                              
                                              • 20. Re: copy filename to iptc description
                                                AndrewUSMC Community Member

                                                Paul,

                                                 

                                                I had some troubles with the code above, so what I did was take the code you had put up with the instructions on how and where to save it and just changed Desc and Description to Title, and it worked! Thank you so much for your help, this script has just saved us a ton of time. Thank you and thank you everyone here for your help.

                                                • 21. Re: copy filename to iptc description
                                                  AndrewUSMC Community Member

                                                  Ok, so I ran into an issue, the code I used won't work on Camera RAW (.CR2), any ideas on what I can do to fix this? Thanks again for any and all of your help.

                                                  • 22. Re: copy filename to iptc description
                                                    Paul Riggott Community Member

                                                    CR2 files are read only so all you can do is amend the xmp file (or create a new xmp if it does not exist) with the required information, as an example...

                                                     

                                                     

                                                    var sels = app.document.selections;
                                                    for(var a in sels){
                                                        setTitle(sels[a].spec);
                                                        }
                                                    function setTitle(thumb){
                                                    var Name = decodeURI(thumb.name).replace(/\.[^\.]+$/, '');
                                                    var file = new File(thumb.path +"/" +Name +".xmp");
                                                    if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
                                                      if(file.exists){
                                                         file.open('r');
                                                         file.encoding = "UTF8";
                                                         file.lineFeed = "unix"; 
                                                         file.open("r", "TEXT", "????");
                                                         var xmpStr = file.read();
                                                         file.close();
                                                         }else{
                                                             var xmpStr='';
                                                             }
                                                         var xmp = new XMPMeta( xmpStr );
                                                        xmp.deleteProperty(XMPConst.NS_DC, "title");
                                                        xmp.appendArrayItem(XMPConst.NS_DC, "title", Name, 0, XMPConst.ALIAS_TO_ALT_TEXT);
                                                        xmp.setQualifier(XMPConst.NS_DC, "title[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default");
                                                         file.open('w');
                                                         file.encoding = "UTF8";
                                                         file.lineFeed = "unix"; 
                                                         file.write( xmp.serialize() );
                                                         file.close();
                                                    };
                                                    
                                                    
                                                     
                                                    • 23. Re: copy filename to iptc description
                                                      cdblach Community Member

                                                      Paul,

                                                       

                                                      I found this script from you: Re: How to Batch copy filename to its metadata Title and used it with great success, but it inserts the filename into the end of the description. Is there a way to modify it to place the filename at the beginning of the description?