8 Replies Latest reply on May 22, 2017 12:42 PM by toddl62332479

    How can I modify IPTC headers with JSX script, without opening images.

    toddl62332479

      I'd like to use Photoshop, and scripting, to modify several IPTC fields in a JPEG, without actually opening the JPEG, and then also rename the JPEG.

       

      Right now, I've got a .JSX script I wrote that will do the following:

       

      1) Ask the user to point to a directory containing JPEG files

      2) Ask the user to input a caption

      3) Open each JPEG in the directory, modify the Author, Caption, and several other fields

      4) Save-As the JPEG to a new directory, with a different name

      5) Close the JPEG

       

      This JSX works great right now.  But if there are 100 images, then it take a long time to complete this task.

       

      I have another .JSX script that will complete some of this work without opening the JPEG in Photoshop.  But this .JSX script only modifies XMP data.  That information is not visible from the Windows file system when I right-click and ask for "details."

       

      How can I write a .JSX script to modify the IPTC metadata without actually opening the JPG, and how can I get Photoshop to rename the file as well?

       

      Thanks,

        • 1. Re: How can I modify IPTC headers with JSX script, without opening images.
          JJMack Most Valuable Participant

          Photoshop can not rename files but you can use Javascript file system support to rename files.    For Photoshop to change IPTC metadata not only would it need to open the files it would also need to write the file.  The Bridge can read and write metadata without opening the document in Photoshop and Bridge can rename files.   Bridge can be scripted but I have never written a Bridge script and there is some kind a Bridge Talk interface between Bridge scripts and Photoshop scripts.  You may want to look at Bridge scripting.

          • 2. Re: How can I modify IPTC headers with JSX script, without opening images.
            toddl62332479 Level 1

            In the last couple of hours, I've written a script that allows Photoshop to modify IPTC information without opening the JPG, and also allows it to rename the JPG without opening or re-saving it.

             

            What I'm missing now is an understanding of how to identify all the metadata that it's possible to change, and how to do that. I can change author and description and copyright notice.  But I want to modify more.

             

            How can I insert my code here to share, and not have it look like a mess?

            • 3. Re: How can I modify IPTC headers with JSX script, without opening images.
              SuperMerlin Level 5

              It would help if you mentioned what fields you want to deal with, as not all fields require the same code.

              • 4. Re: How can I modify IPTC headers with JSX script, without opening images.
                toddl62332479 Level 1

                Right now I can modify "description" "title" "rights" and "creator":

                 

                    xmp.deleteProperty(XMPConst.NS_DC, "description");

                    xmp.setLocalizedText(XMPConst.NS_DC, "description", null, "x-default", TheCaption);

                    xmp.deleteProperty(XMPConst.NS_DC, "title");

                    xmp.setLocalizedText(XMPConst.NS_DC, "title", null, "x-default", TheCaption);

                    xmp.deleteProperty(XMPConst.NS_DC, "rights");

                    xmp.setLocalizedText(XMPConst.NS_DC, "rights", null, "x-default", TheCopyrightNoticeMessage);

                    xmp.deleteProperty(XMPConst.NS_DC, "creator");

                    xmp.appendArrayItem(XMPConst.NS_DC, "creator", ThePhotographer, 0, XMPConst.ARRAY_IS_ORDERED);

                 

                After this, I modify the JPG:

                 

                    if (xmpf.canPutXMP( xmp ))

                      {

                        xmpf.putXMP( xmp );

                      }

                    xmpf.closeFile( XMPConst.CLOSE_UPDATE_SAFELY );

                 

                This is all accomplished without Photoshop having to open the JPG.

                 

                I'd like to modify "description writer" "copyright status" "copyright info URL", "Websites(s)" in the IPTC tab, and possibly "date created", "City" "State" and "Country" in the IPTC tab.

                 

                Some of these fields are visible from within the Windows file system, when you right-click on a JPG and look at the "details" tab.  Others are only visible inside Photoshop under the file info menu option.

                 

                Thanks.

                • 5. Re: How can I modify IPTC headers with JSX script, without opening images.
                  SuperMerlin Level 5

                  Hope these help...

                   

                  xmp.appendArrayItem( XMPConst.NS_DC, "creator", "Creator", 0, XMPConst.ARRAY_IS_ORDERED );
                  xmp.setLocalizedText( XMPConst.NS_DC, "title", null, "en-US", "Title" );
                  xmp.setProperty(XMPConst.NS_PHOTOSHOP, "AuthorsPosition", "Author Position");
                  xmp.setProperty(XMPConst.NS_PHOTOSHOP, "Headline", "Headline");
                  xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", "Caption/Description" ); 
                  xmp.setProperty(XMPConst.NS_PHOTOSHOP, "DateCreated", new XMPDateTime(new Date()), XMPConst.XMPDATE);
                  var Keys=["Keyword1","Keyword2","Etc."];
                  for(var s in Keys){
                  xmp.appendArrayItem(XMPConst.NS_DC, "subject", Keys[s], 0,XMPConst.PROP_IS_ARRAY);
                  }
                  xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiAdrCtry", "England" );
                  xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiEmailWork", "Joe.Bloggs@email.com" );
                  xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiAdrCity","Leeds");
                  xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiAdrExtadr","Address");
                  xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiAdrPcode","LS12PP");
                  xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiAdrRegion","West Yorkshire");
                  xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiTelWork","0132999999");
                  xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiUrlWork","www.mysite.co.uk");
                  xmp.setProperty( XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:Location","Sub Location");
                  xmp.setProperty( XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:IntellectualGenre","Itellectual Genre");
                  xmp.appendArrayItem( XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:SubjectCode","IPTC Subject Code",0,XMPConst.PROP_IS_ARRAY);
                  xmp.appendArrayItem( XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:Scene","IPTC Scene Code",0,XMPConst.PROP_IS_ARRAY);
                  xmp.setProperty( XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:CountryCode", "ISO Country Code" );
                  xmp.setProperty(XMPConst.NS_PHOTOSHOP, "City", "London");
                  xmp.setProperty(XMPConst.NS_PHOTOSHOP, "State", "State/Province");
                  xmp.setProperty(XMPConst.NS_PHOTOSHOP, "Country", "Britain");
                  xmp.setProperty(XMPConst.NS_PHOTOSHOP, "CaptionWriter", "Description Writer");
                  xmp.setProperty(XMPConst.NS_PHOTOSHOP, "TransmissionReference", "Job Identifier");
                  xmp.setProperty(XMPConst.NS_PHOTOSHOP, "Instructions", "Instructions");
                  xmp.setProperty(XMPConst.NS_PHOTOSHOP, "Credit", "Credit Line");
                  xmp.setProperty(XMPConst.NS_PHOTOSHOP, "Source", "Source");
                  xmp.setLocalizedText( XMPConst.NS_DC, "rights", null, "x-default", "Copyright Notice" ); 
                  xmp.appendArrayItem( XMPConst.NS_XMP_RIGHTS, "UsageTerms","Rights Usage",0,XMPConst.PROP_IS_ARRAY);
                  
                  
                  
                  • 6. Re: How can I modify IPTC headers with JSX script, without opening images.
                    toddl62332479 Level 1

                    Thanks. I'll give that a shot.  Also, I think I'll try to insert my code in here using "advanced editor" and "insert raw HTML."

                    // // // Right now, this is saved in a .jsx file on my desktop. // If I click it, it opens Photoshop, and // I am prompted to select a directory of images. // Then I am asked to enter a caption, and then my name. // Then Photoshop inserts that information into each JPG // and also renames the JPGs image_1.jpg, image_2.jpg, image_3.jpg, etc., // all without opening any images. // I want to know how to modify even more IPTC or metadata // than what I am modifying now.  Right now I modify four fields. // It's hard to guess what needs to be done to modify other fields. // var picFolder = Folder.selectDialog("Select a folder to process"); TheCaption = Window.prompt ("Enter a caption for the photos."); ThePhotographer = Window.prompt ("What's the photographer's name?."); TheCopyrightNoticeMessage = "This image is copyrighted"; var i = 0; var pics = Folder(picFolder).getFiles("*.JPG"); if ( !ExternalObject.AdobeXMPScript ) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript'); for (f in pics)   {     file = pics[f];     var xmpf = new XMPFile( File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE );     var xmp = xmpf.getXMP();     xmp.deleteProperty(XMPConst.NS_DC, "description");     xmp.setLocalizedText(XMPConst.NS_DC, "description", null, "x-default", TheCaption);     xmp.deleteProperty(XMPConst.NS_DC, "title");     xmp.setLocalizedText(XMPConst.NS_DC, "title", null, "x-default", TheCaption);     xmp.deleteProperty(XMPConst.NS_DC, "rights");     xmp.setLocalizedText(XMPConst.NS_DC, "rights", null, "x-default", TheCopyrightNoticeMessage);     xmp.deleteProperty(XMPConst.NS_DC, "creator");     xmp.appendArrayItem(XMPConst.NS_DC, "creator", ThePhotographer, 0, XMPConst.ARRAY_IS_ORDERED);     if (xmpf.canPutXMP( xmp ))       {         xmpf.putXMP( xmp );       }     xmpf.closeFile( XMPConst.CLOSE_UPDATE_SAFELY );     i = i + 1;     file.rename("image_" + i + ".jpg");   } //
                    • 7. Re: How can I modify IPTC headers with JSX script, without opening images.
                      SuperMerlin Level 5

                      To insert code on this forum, goto advanced editor, click >> and select javascript.

                      The raw html didn't work out as it should

                      • 8. Re: How can I modify IPTC headers with JSX script, without opening images.
                        toddl62332479 Level 1
                        //
                        // Right now, this is saved in a .jsx file on my desktop.
                        // If I click it, it opens Photoshop, and 
                        // I am prompted to select a directory of images.
                        // Then I am asked to enter a caption, and then my name.
                        // Then Photoshop inserts that information into each JPG
                        // and also renames the JPGs image_1.jpg, image_2.jpg, image_3.jpg, etc.,
                        // all without opening any images.
                        // I want to know how to modify even more IPTC or metadata
                        // than what I am modifying now.  Right now I modify four fields.
                        // It's hard to guess what needs to be done to modify other fields.
                        // 
                        
                        var picFolder = Folder.selectDialog("Select a folder to process"); 
                        TheCaption = Window.prompt ("Enter a caption for the photos."); 
                        ThePhotographer = Window.prompt ("What's the photographer's name?."); 
                        TheCopyrightNoticeMessage = "This image is copyrighted"; 
                        var i = 0; 
                        var pics = Folder(picFolder).getFiles("*.JPG");
                        if ( !ExternalObject.AdobeXMPScript ) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
                        for (f in pics)
                          {
                            file = pics[f]; 
                            var xmpf = new XMPFile( File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE );
                            var xmp = xmpf.getXMP();
                        
                            xmp.deleteProperty(XMPConst.NS_DC, "description");
                            xmp.setLocalizedText(XMPConst.NS_DC, "description", null, "x-default", TheCaption);
                            xmp.deleteProperty(XMPConst.NS_DC, "title");
                            xmp.setLocalizedText(XMPConst.NS_DC, "title", null, "x-default", TheCaption);
                            xmp.deleteProperty(XMPConst.NS_DC, "rights");
                            xmp.setLocalizedText(XMPConst.NS_DC, "rights", null, "x-default", TheCopyrightNoticeMessage);
                            xmp.deleteProperty(XMPConst.NS_DC, "creator");
                            xmp.appendArrayItem(XMPConst.NS_DC, "creator", ThePhotographer, 0, XMPConst.ARRAY_IS_ORDERED);
                            if (xmpf.canPutXMP( xmp ))
                              {
                                xmpf.putXMP( xmp );
                              }
                            xmpf.closeFile( XMPConst.CLOSE_UPDATE_SAFELY );
                            i = i + 1;
                            file.rename("image_" + i + ".jpg");
                          }