1

Is there an equivalent of deleteProperty(XMPConst.NS_DC, "description”) or some way to clear out EXIF:ImageDescription, XMP-dc:Description and IPTC:Caption-Abstract with a Photoshop Script (ie, JavaScript or AppleScript)?

I am trying to remove the tags/descriptions below from TIF, PSD and PSB images:

  • [EXIF:IFD0] ImageDescription
  • [XMP:XMP-dc] Description
  • [IPTC] Caption-Abstract

I can do this with Exiftool with this code:

exiftool -m -overwrite_original_in_place -EXIF:ImageDescription= -XMP-dc:Description= -IPTC:Caption-Abstract= FILE

While that works great for me, I have lots of vendors that would need this in their workflows so it would be easier for them to use an action with the Photoshop Events Manager "On Document Open", or via an Automator script (JavaScript or AppleScript) in their workflows than installing ExifTool. Looking for some help to do this...

I don’t have much coding experience, but I found the JavaScript code below on PS-Scripts as a starting point. This code doesn't require Photoshop which I like and could be done with Automator, but it only references the one tag. Also, I don’t need to write anything to the tags as this code does (I’d prefer just to delete or wipe the content and/or tags so they don’t show up).

Code: Select allvar f = File("/c/captures/a.jpg");
setDescription(f,"My new description");

function setDescription( file, descStr ){
if ( !ExternalObject.AdobeXMPScript ) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
        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", descStr );
      if (xmpf.canPutXMP( xmp )) {
         xmpf.putXMP( xmp );
      }
      xmpf.closeFile( XMPConst.CLOSE_UPDATE_SAFELY );
}

And below is an attempt at the JavaScript that would be used as a Photoshop Event on "Open Document"; but again I don't know how to amend to ensure all 3 tags reference above are cleared:

function removeDescription() {
    whatApp = String(app.name);
    if(whatApp.search("Photoshop") > 0)  
          if(!documents.length) {
        alert("There are no open documents. Please open a file to run this script.")
        return;
        }
        if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
        var xmp = new XMPMeta( activeDocument.xmpMetadata.rawData);
             xmp.deleteProperty(XMPConst.NS_DC, "description");
            app.activeDocument.xmpMetadata.rawData = xmp.serialize();
         }
}
removeDescription();

Finally, below was an alternate that was tried that wipes the Description, ImageDescription and Caption-Abstract on TIFFs and PNGs on the first try, but takes running through twice to work on a PSD/PSB/JPG. I think it has to do with the interaction between Description, ImageDescription and Caption-Abstract, and the solution possibly resides with amp.setLocalizedText to nothing?

function removeMetadata() {
    whatApp = String(app.name);
    if(whatApp.search("Photoshop") > 0)  { 
         if(!documents.length) {
        alert("There are no open documents. Please open a file to run this script.")
        return;
        }
        if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
        var xmp = new XMPMeta( activeDocument.xmpMetadata.rawData);
            if (xmp.doesArrayItemExist(XMPConst.NS_DC, "description", 1))
            {
                xmp.deleteArrayItem(XMPConst.NS_DC, "description", 1);
            }
            app.activeDocument.xmpMetadata.rawData = xmp.serialize();

            debugger
         }
}
removeMetadata();
Chris
  • 35
  • 5
  • 1
    Always link to from where you _found_ something. And maintain indention. – AmigoJack Feb 16 '23 at 01:56
  • @AmigoJack fixed. Looks like the indentation was lost due to incorrect markups at the time of post. – Chris Feb 16 '23 at 04:04
  • Why don't you just use `exiftool` on the Mac if that does what you want? – Mark Setchell Feb 16 '23 at 07:32
  • ExifTool works well for me, but despite what I may think, it's not always about me... I can more easily have it automatically run by many vendors in their workflows as they open/create/work on the files via the Photoshop Scripts Manager, and doesn't require them to install ExifTool. – Chris Feb 16 '23 at 16:04
  • Photoshop uses JavaScript not Java! Also, is this what you [want](https://community.adobe.com/t5/photoshop-ecosystem-discussions/is-there-an-equivalent-of-deleteproperty-xmpconst-ns-dc-quot-description-for-exif-imagedescription/td-p/13583041)? – Ghoul Fool Feb 20 '23 at 11:50
  • @GhoulFool, thank you for the catch on the typo in that one spot... yes, I meant Javascript. I'm not able to edit now with too many pending edits but will try again later. Also, the post you referenced is actually mine on this same topic, posed a different way in another forum. – Chris Feb 21 '23 at 16:19
  • @Chris Who knew?! You can use `app.activeDocument.info.caption = " ";` and reduce the image Description to a single space - `""` doesn't do anything - but that's probably not what you're after. – Ghoul Fool Feb 21 '23 at 20:51

1 Answers1

0

Here is an example Python script that uses the Pillow library to remove the metadata descriptions.

from PIL import Image

# Open the image file
image = Image.open('example.jpg')

# Remove the EXIF:ImageDescription metadata field
image.info.pop('EXIF:ImageDescription', None)

# Remove the XMP-dc:Description metadata field
image.info.pop('XMP-dc:Description', None)

# Remove the IPTC:Caption-Abstract metadata field
image.info.pop('IPTC:Caption-Abstract', None)

# Save the modified image file
image.save('example_modified.jpg')

Change "example.jpg" to your needs.

there may be other metadata fields that contain descriptions, depending on the specific image file format and how it was created. You may need to modify the script to remove additional fields if necessary.

Cawa
  • 1
  • 3
  • Unfortunately that code doesn't fulfil the desired purpose - it retrieves the metadata fields from the info structure, but it doesn't remove them from the file. Also, it's not 100% clear but I think the OP was asking for a "photoshop script" - see https://helpx.adobe.com/photoshop/using/scripting.html – Brendan Quinn Feb 16 '23 at 10:08
  • Thank you @BrendanQuinn, that is correct, I was looking for a Photoshop script (JavaScript) solution. I updated the post to make it more clear and with added context. However, I guess this could also be done with a solution that would work with Automator. So, if what you're saying is that the Python script above clears the associated data but keeps the tags that could be an alternate solution. – Chris Feb 16 '23 at 17:34