How to remove XMP data? Some namespaces apparently read-only
I have been banging my head against the wall to write a script that removes EXIF, EXIFEX, and EXIF-AUX data from files. I'm using Bridge 2022 and Photoshop 2023.
After numerous attempts, what happens is that Bridge will run a script flawlessly and APPEAR to have removed data, but purging cache or opening a file in a different application shows that it didn't happen.
var Thumbs = app.document.selections; //apply to all selected thumbs
if(ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript'); //load library for metadata
for(var a in Thumbs){
try{
if(Thumbs[a].hasMetadata){
var ThumbsMeta = Thumbs[a].synchronousMetadata; //get metadata
var ThumbsXMP = new XMPMeta(ThumbsMeta.serialize());
XMPUtils.removeProperties(ThumbsXMP, '', '', XMPConst.REMOVE_ALL_PROPERTIES);
var ThumbsUpdatedPacket = ThumbsXMP.serialize();//XMPConst.SERIALIZE_USE_COMPACT_FORMAT); //update metadata object
Thumbs[a].metadata = new Metadata(ThumbsUpdatedPacket); //write to file
}
}
catch(e){
alert(e + ' ' + e.line);
}
}
This script should remove everything. Run it on a JPEG and look at what Bridge reports, then purge cache and look again. Complete fail.
This is a comparable Photoshop script, open a JPEG and run this then take a look.
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
XMPUtils.removeProperties(xmp, "", "", XMPConst.REMOVE_ALL_PROPERTIES);
app.activeDocument.xmpMetadata.rawData = xmp.serialize();
I have tried numerous variations on this, I have a much longer script where I try to delete only parts of these namespaces. WTF? Is this by design, that a bunch of metadata is read-only but Bridge caches it as if it was actually processed?
