Skip to main content
Gibson Editions
Inspiring
June 13, 2023
Answered

Bug in clearing metadata script

  • June 13, 2023
  • 1 reply
  • 512 views

I use this script to anonomise files i send out for outsourcing. However one part of the script  does not sucessfully clear the metadata apply an empty template to the selected files. Anybody got any idea where im going wrong or maybe there is a simpler way to clear the metadata. 

 

 

 

 

 

// https://forums.adobe.com/message/8934040#8934040
#target bridge
if (BridgeTalk.appName == "bridge"){
var clearMetadata = MenuElement.create( "command", "Clear Metadata", "at the end of Tools");
}
clearMetadata.onSelect = function (){

 var selectedThumbnails = app.document.getSelection();
 var filesArray = [];
    var modified = 0;
    for (var i = 0; i < selectedThumbnails.length; ++i) {
                        var val = decodeURI(selectedThumbnails[i].name);
                        var f = new File (decodeURI(selectedThumbnails[i].path))
            val = val.replace(/\.[^\.]+$/, '');
p = (val.match(/_0/).index)+1
val =val.substr(p,4)

newName = val + '.psd'
var f1 = new File (f.parent + "/" + newName)
if (f1.exists == true){newName = val + '_1' + '.psd'}
        selectedThumbnails[i].name = newName

var f2 = new File (f.parent + "/" + newName)

        filesArray.push(f2.path + '/' + f2.name)
        
				filesArray = eval(filesArray.toSource());}
				
for (var i = 0; i < filesArray.length; ++i) {          
var t = new Thumbnail (File (filesArray[i])) 
var metadata = t.synchronousMetadata;
metadata.applyMetadataTemplate("clearall", "replace")
            }
   // if (modified == i)
           // alert('All files modified');
    //else
    //    alert('Modified ' + modified +' of ' + i + ' files.');
  //debugger

        
    $.sleep(500);     

for (var i = 0; i < filesArray.length; i++) {
//SWITCHING TO PHOTOSHOP
		bt = new BridgeTalk();
                
        bt.target = 'photoshop';
        bt.body =  'app.open(new File("' + filesArray[i] + '"))'
        bt.send();
}


//RUNNING IN PHOTOSHOP TO RUN SCRIPT ON ALL OPEN FILES.... 
	bt1 = new BridgeTalk();
        bt1.target = 'photoshop';
        bt1.body = script.toString() + "; script();" ;
        bt1.send();





//CALLING EXTERNAL SCRIPT
function script(){
        BridgeTalk.appName == "photoshop"
    /*amend with your script name*/
var scriptName = "8bit.jsx"; 
var s = File(app.path + "/presets/scripts/Lyr/" + scriptName);
$.evalFile(s);
}



};
This topic has been closed for replies.
Correct answer Lumigraphics

applyMetadataTemplate is indeed broken in Bridge 2023. And Adobe XMP doesn't clear all fields, regardless of usage.

Download my Run EXIFTool script as Greg suggests, that has a preset to clear metadata. In the developmental folder.

https://www.dropbox.com/sh/mg817g9a9ymbasi/AADTmXUVxmFfM58bcyYE7yiwa?dl=0

1 reply

gregreser
Legend
June 14, 2023

It seems to be a bug in Bridge 2023. I can't get applyMetadataTemplate to work at all in 2023 but it does work in 2022.

 

You could clear the metadata from individual properties using deleteProperty or from all properties in a namespace using XMPUtils.removeProperties

 

    for (var i = 0; i < filesArray.length; i++){
        var t = filesArray[i];
        var metadata = t.synchronousMetadata;
        // Get the XMP packet as a string and create the XMPMeta object
        var xmpData = new XMPMeta(metadata.serialize());
       
        // remove all properties in a namespace
        XMPUtils.removeProperties(xmpData, 'http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/', '', XMPConst.REMOVE_ALL_PROPERTIES); 
        // remove a single property  
        xmpData.deleteProperty('http://purl.org/dc/elements/1.1/', 'title'); 
        
        // Write the packet back to the selected file
        var updatedPacket = xmpData.serialize(XMPConst.SERIALIZE_OMIT_PACKET_WRAPPER | XMPConst.SERIALIZE_USE_COMPACT_FORMAT);
        t.metadata = new Metadata(updatedPacket);

        }

You need to be careful about deleting entire namespaces because some properties, like technical data, might be important for viewing or managing the image later.

 

To delete all the IPTC Core properties, you would do this:

XMPUtils.removeProperties(xmpData, 'http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/', '', XMPConst.REMOVE_ALL_PROPERTIES);
xmpData.deleteProperty('http://ns.adobe.com/photoshop/1.0/', 'AuthorsPosition');
xmpData.deleteProperty('http://ns.adobe.com/photoshop/1.0/', 'CaptionWriter');
xmpData.deleteProperty('http://ns.adobe.com/photoshop/1.0/', 'City');
xmpData.deleteProperty('http://ns.adobe.com/photoshop/1.0/', 'Country');
xmpData.deleteProperty('http://ns.adobe.com/photoshop/1.0/', 'Credit');
xmpData.deleteProperty('http://ns.adobe.com/photoshop/1.0/', 'DateCreated');
xmpData.deleteProperty('http://ns.adobe.com/photoshop/1.0/', 'Headline');
xmpData.deleteProperty('http://ns.adobe.com/photoshop/1.0/', 'Instructions');
xmpData.deleteProperty('http://ns.adobe.com/photoshop/1.0/', 'Source');
xmpData.deleteProperty('http://ns.adobe.com/photoshop/1.0/', 'State');
xmpData.deleteProperty('http://ns.adobe.com/photoshop/1.0/', 'TransmissionReference');
xmpData.deleteProperty('http://ns.adobe.com/xap/1.0/rights/', 'UsageTerms');
xmpData.deleteProperty('http://purl.org/dc/elements/1.1/', 'creator');
xmpData.deleteProperty('http://purl.org/dc/elements/1.1/', 'description');
xmpData.deleteProperty('http://purl.org/dc/elements/1.1/', 'rights');
xmpData.deleteProperty('http://purl.org/dc/elements/1.1/', 'subject');
xmpData.deleteProperty('http://purl.org/dc/elements/1.1/', 'title');
xmpData.deleteProperty('http://ns.adobe.com/xap/1.0/rights/', 'UsageTerms');

 

On the other hand, If you want to clear all metadata, note that some metadata properties are read only and can't be deleted by a script. See: How to remove XMP data? Some namespaces apparently read-only  The solution to that problem was to run ExifTool from a script. Since you were going to use a metadata template to clear data, you should be able to clear the same properties using a script, so this will be an issue for you. I just thought I would mention ExifTool in case you need more options.

LumigraphicsCorrect answer
Legend
June 15, 2023

applyMetadataTemplate is indeed broken in Bridge 2023. And Adobe XMP doesn't clear all fields, regardless of usage.

Download my Run EXIFTool script as Greg suggests, that has a preset to clear metadata. In the developmental folder.

https://www.dropbox.com/sh/mg817g9a9ymbasi/AADTmXUVxmFfM58bcyYE7yiwa?dl=0

Gibson Editions
Inspiring
June 16, 2023

Many Thanks for your help I will give this a go