Bridge Script to Remove Photoshop DocumentAncestors Metadata

Adobe Community Professional ,
May 31, 2017 May 31, 2017

Copy link to clipboard

Copied

Bloated files that contain “excess” Photoshop DocumentAncestors metadata have been causing a few users some grief (65mb down to 110kb)!

Re: Photoshop saving issue (FILES TOO LARGE)

There is a script for Photoshop to remove this metadata, however as this requires an open/save it is not great for files that contain lossy compression. Bridge is the obvious place to remove this metadata. I have hacked a different script to remove this DocumentAncestor metadata.

I don’t understand why Bridge requires a 2 step process! All this time I thought that the code was bad, when it was “working fine”.

Step 1: Run the Bridge script to remove DocumentAncestors metadata (the file size does not change, when it “should”)

Step 2: Apply a secondary metadata change in Bridge, such as adding/removing a temporary keyword, or rotating clockwise and then rotating back counterclockwise again to “force the image to reset”

The second step for whatever reason will force the file to update and take into account the removal of the DocumentAncestors metadata and then applies the file size reduction!

The code:

// https://forums.adobe.com/thread/290238

// https://forums.adobe.com/thread/1880847

// https://forums.adobe.com/thread/2340460

#target bridge // let EntendScript know what app the script is for

clearDocumentAncestors = {};// create an object

clearDocumentAncestors.execute = function(){// create a method for that object

  var sels = app.document.selections;// store the array of selected files

  for (var i = 0; i < sels.length; i++){//loop though that array

    var md = sels.synchronousMetadata;// get the metadata for the file

     md.namespace = "http://ns.adobe.com/photoshop/1.0/";// set the namespace

     md.DocumentAncestors = " ";//set the porperty

  }

}

// this script only works in bridge

if (BridgeTalk.appName == "bridge"){

  //creage the munuItem

  var menu = MenuElement.create( "command", "Clear DocumentAncestors in metadata", "at the end of Tools");

  menu.onSelect = clearDocumentAncestors.execute;

}

TOPICS
Scripting

Views

10.1K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 04, 2017 Jun 04, 2017

Copy link to clipboard

Copied

Ok, deleted the old script out of the CC 2017 Startups folder, and placed it with the new one in it giving it the same title.

This time I did not call up extendscript

Same error as pictured when I start Bridge:

Screen Shot 2017-06-04 at 10.17.49 AM.png

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 04, 2017 Jun 04, 2017

Copy link to clipboard

Copied

Am I supposed to have a "Purge Cache for Selected" script?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 04, 2017 Jun 04, 2017

Copy link to clipboard

Copied

Paste the script from here into ExtendScript Toolkit then save it out to the relevant folder, this should then be a clean file and should work.

I still think you editors are not using plain text.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 04, 2017 Jun 04, 2017

Copy link to clipboard

Copied

Ok, I got it to load successfully that way   Thanks for staying with me. Now  to try it on the testfiles.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 04, 2017 Jun 04, 2017

Copy link to clipboard

Copied

Works successfully on the jpeg, but the psd keeps the 67 MB reading until I try the Rotate View command. Then it is 110 k.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 04, 2017 Jun 04, 2017

Copy link to clipboard

Copied

Jive's edit function is acting up again.

I used to be able to create jsx scripts with Mac's TextEcit, but wiser to just use the Extendscript Toolkit. It does save me from the extra step of changing the extension to jsx

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 05, 2017 Jun 05, 2017

Copy link to clipboard

Copied

I’m having the same issue with copy direct from the forum pasted into ESTK (on a Mac).

I had to comment out line 17 in order to get the script to work (the first script works fine, it is the second one that has issues).

Not a big deal, still looking to see what the issue is, it is not obvious to me!

EDIT: Invisible characters if this helps…

show-invisibles.png

Even copy/paste from Chrome to ESTK in Windows results in the same error when saved in Windows and then run on the Mac.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 14, 2017 Jun 14, 2017

Copy link to clipboard

Copied

Forgot to link to the Photoshop script that can be setup for use with the Script Events Manager to auto run on open, save and export:

Re: Inflated JPG File Size  - Photoshop Document:Ancestors Metadata

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 18, 2017 Jun 18, 2017

Copy link to clipboard

Copied

I have just updated my blog with with all of the known solutions to this issue:

Prepression: Metadata Bloat – photoshop:DocumentAncestors

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 26, 2017 Jun 26, 2017

Copy link to clipboard

Copied

SuperMerlin as kindly donated some Photoshop code that will purge this metadata on an folder of JPG/TIF/PSD files, from Photoshop – without opening the files into Photoshop (now that does sound like some crazy voodoo magic!)

Re: How can I remove junk RAW DATA from file?

// https://forums.adobe.com/message/9671488#9671488

#target photoshop; 

var inputFolder= Folder.selectDialog ("Please select folder to process"); 

if(inputFolder != null){ 

var fileList  = inputFolder.getFiles(/\.(jpg|tif|psd)$/i); 

for(var a in fileList){delFileAncestorsMeta(fileList);} 

function delFileAncestorsMeta(selectedFile) {         

if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");      

var xmpFile = new XMPFile( selectedFile.fsName, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_UPDATE | XMPConst.OPEN_USE_SMART_HANDLER );  

var xmp = xmpFile.getXMP(); 

xmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "DocumentAncestors"); 

if (xmpFile.canPutXMP(xmp)) {  

        xmpFile.putXMP(xmp); 

         xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);  

         }               

};   

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 04, 2018 Sep 04, 2018

Copy link to clipboard

Copied

thank you!!!

is it possible to include subfolders?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Sep 04, 2018 Sep 04, 2018

Copy link to clipboard

Copied

LATEST

The Bridge script is working on selected files, not folders. It is beyond my current newb scripting abilities I am afraid, however I do have a work around…

Use the View menu > Show items from Subfolders command and also untick the Show folders command, then select all files and run the script.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines