Any gurus here with Photoshop scripting knowledge that can help me clear out just the 4 metadata fields below with a Photoshop script?
First, let me say that I know this can easily be done with the ExifTool code below:
While this works great for me, I would like to do this same thing with a Photoshop script, if possible, since all of the sites that will be using this don't have ExifTool. Also, with a script I can ensure it automatically gets checked/done when a file is opened/saved in Photoshop.
Below is the .jsx script I have so far:
This script is invoked with the Photoshop Scripts Events Manager on Document Open.
Observations:
TIFF: Works as desired... all 4 fields are cleared.
PSD, PSB and JPG: 3 of the 4 fields ([EXIF]ImageDescription, [IPTC]Caption-Abstract and [XMP-Photoshop]DocumentAncestors) are cleared as I'd like. However, for these image formats, the data that was once in [EXIF]ImageDescription is now in [XMP-dc]Description.
I noticed that if I open the PSD, PSB and JPG files a second time and run through the script, then everything gets cleared out on these files as well.
If I add
Assumptions:
I believe this has something to do with how the [EXIF]ImageDescription and [XMP-dc]Description work together, but not sure how to resolve. It would appear this script is clearing the [XMP-dc]Description, pulling the contents of the [EXIF]ImageDescription into it, which then clears the [EXIF]ImageDescription. Since [EXIF]ImageDescription was cleared by the script the first time, running it a second time puts that cleared value of the XMP-dcescription into itself, thereby freeing all of them up.
If my assumptions are correct, this leaves a few questions...
Questions:
1) Is there a way to amend the code to clear out the [EXIF]ImageDescription first? If so, how?
2) If not, any suggestions how I could modify the code to run only once to ensure the PSD/PSB/JPG is fixed the first time? I tried the two things below that didn't work:
- Called the function from within the script twice
- Added the script to 2 events (On Open & On Close)
PS: I don't want to delete all metadata, just these fields.
References:
Test image and .jsx script are attached for reference.
Posted similar question to PS-Scripts, Adobe Support Community and Stack Overflow... no solutions yet.
I found this post on Exiftool's forum that was helpful in understanding the interplay of the description fields.
- [EXIF] ImageDescription
- [XMP-dc] Description
- [IPTC] Caption-Abstract
- [XMP-Photoshop] DocumentAncestors
First, let me say that I know this can easily be done with the ExifTool code below:
Code:
exiftool -m -overwrite_original_in_place -EXIF:ImageDescription= -XMP:dc:Description= -IPTC:Caption-Abstract= [DIR]
While this works great for me, I would like to do this same thing with a Photoshop script, if possible, since all of the sites that will be using this don't have ExifTool. Also, with a script I can ensure it automatically gets checked/done when a file is opened/saved in Photoshop.
Below is the .jsx script I have so far:
JSX:
function deleteUnwantedMetadata() {
whatApp = String(app.name);
if(whatApp.search("Photoshop") > 0) {
if(!documents.length) {
alert("No open documents. Open a file to run script.")
return;
}
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var xmp = new XMPMeta( activeDocument.xmpMetadata.rawData);
xmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "DocumentAncestors");
if (xmp.doesArrayItemExist(XMPConst.NS_DC, "description", 1))
{
xmp.deleteArrayItem(XMPConst.NS_DC, "description", 1);
}
app.activeDocument.xmpMetadata.rawData = xmp.serialize();
}
}
deleteUnwantedMetadata();
This script is invoked with the Photoshop Scripts Events Manager on Document Open.
Observations:
TIFF: Works as desired... all 4 fields are cleared.
PSD, PSB and JPG: 3 of the 4 fields ([EXIF]ImageDescription, [IPTC]Caption-Abstract and [XMP-Photoshop]DocumentAncestors) are cleared as I'd like. However, for these image formats, the data that was once in [EXIF]ImageDescription is now in [XMP-dc]Description.
I noticed that if I open the PSD, PSB and JPG files a second time and run through the script, then everything gets cleared out on these files as well.
If I add
xmp.setLocalizedText(XMPConst.NS_DC, "description", null, "x-default", " ");
below xmp.deleteArrayItem(XMPConst.NS_DC, "description", 1);.
above, this will at least clear everything out and just include a space for the field, but would rather have the filed empty if possible (null doesn't appear to work here).Assumptions:
I believe this has something to do with how the [EXIF]ImageDescription and [XMP-dc]Description work together, but not sure how to resolve. It would appear this script is clearing the [XMP-dc]Description, pulling the contents of the [EXIF]ImageDescription into it, which then clears the [EXIF]ImageDescription. Since [EXIF]ImageDescription was cleared by the script the first time, running it a second time puts that cleared value of the XMP-dcescription into itself, thereby freeing all of them up.
If my assumptions are correct, this leaves a few questions...
Questions:
1) Is there a way to amend the code to clear out the [EXIF]ImageDescription first? If so, how?
2) If not, any suggestions how I could modify the code to run only once to ensure the PSD/PSB/JPG is fixed the first time? I tried the two things below that didn't work:
- Called the function from within the script twice
- Added the script to 2 events (On Open & On Close)
PS: I don't want to delete all metadata, just these fields.
References:
Test image and .jsx script are attached for reference.
Posted similar question to PS-Scripts, Adobe Support Community and Stack Overflow... no solutions yet.
I found this post on Exiftool's forum that was helpful in understanding the interplay of the description fields.