Bug in clearing metadata script
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);
}
};