Skip to main content
Participant
November 29, 2023
Answered

Edit metadata title to equal filename

  • November 29, 2023
  • 5 replies
  • 2325 views

I want to create a simple Adobe Bridge metadata template where the only change is to add the existing filename to the metadata title.  

 

i.e. my filename is; Some exciting descriptive title.jpg and I want that image metadata title to be Some exciting descriptive title.  This will be used to batch-update a folder of carefully named images so each carries its filename in the metadata title of that image.

 

I have many hundred images to process once I get this working. Cut-and-past the filename is a non-starter.

 

I have tried many things, including the above, which, of course, does not work.

Any guidance is gratefully accepted, Regards Paul

Correct answer Stephen Marsh

I don't have a ready-made script for this task in Photoshop, I would need to write it.

 

Bridge is more common for this, I do have a Bridge script:

 

// https://imagesimple.wordpress.com/2011/08/24/cs5-filename-to-title-script/
#target bridge
   if( BridgeTalk.appName == "bridge" ) {
FT = MenuElement.create("command", "Add FileName to Title", "at the end of Tools");
}
FT.onSelect = function () {
   AddFilenameToTitle();
   }
function AddFilenameToTitle(){
var thumbs = app.document.selections;
if(!thumbs.length) return;
if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new
ExternalObject("lib:AdobeXMPScript");
for(var a in thumbs){
var selectedFile = thumbs[a].spec;
var Title = decodeURI(selectedFile.name).replace(/\.[^\.]+$/, '')
      var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN,
XMPConst.OPEN_FOR_UPDATE);
  var myXmp = myXmpFile.getXMP();
        myXmp.deleteProperty(XMPConst.NS_DC, "title");
        myXmp.appendArrayItem(XMPConst.NS_DC, "title", Title, 0,
XMPConst.ALIAS_TO_ALT_TEXT);
        myXmp.setQualifier(XMPConst.NS_DC, "title[1]",
"http://www.w3.org/XML/1998/namespace", "lang", "x-default");
        if (myXmpFile.canPutXMP(myXmp)) {
        myXmpFile.putXMP(myXmp);
         myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
         }
    }
}

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

5 replies

Stephen Marsh
Community Expert
Community Expert
November 30, 2023

@AndrewPaulCooper5919847 

 

Please try the scripts added and provide feedback and or mark correct answers.

Participant
December 1, 2023

There is a lot to learn here, but there are some great answers and yes I will go and learn how to use scripts, then try them, then report back.  Thank you all for your feedback.  Paul

Participant
December 1, 2023

YAY!  OK, quite a learning curve there as I have not used scripts in Adobe before but I was successful.

I used Stephen's first Bridge script and 53 files instantly had the metadata updated.

It just worked.

I am going to stop for a bit (otherwise my brain will simply explode) but I will try the Photoshop examples over the weekend.

Thank you so much, Stephen - that is EXACTLY what I wanted.

 

Lumigraphics;  I have not tried your example as Stephens worked but thank you for taking the effort to post it.

 

 

Legend
November 30, 2023

This is much easier to do in Bridge simply because you need a way to select images to edit.

Here is another Bridge function:

function ftAddFilenameToTitle(){
    try{
        var ftThumbs = app.document.selections; //get selected thumbnails
        if (!ftThumbs.length) return; //nothing selected
        if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
        for(var a in ftThumbs){ //loop through thumbs
            if(!ftThumbs[a].container){
                var ftTitle = ftThumbs[a].name; //get filename
                //remove filename after last dash character
                //to remove filename after dash, uncomment lines 69-73
                ftTitle = ftTitle.split('-');
                while(ftTitle.length > 1){
                    ftTitle.length--;
                    }
                ftTitle = ftTitle.join('-');
                //remove filename after last period character
                ftTitle = ftTitle.split('.');
                if(ftTitle.length > 1){
                    ftTitle.length--;
                    }
                ftTitle = ftTitle.join('.');
                var ftMeta = ftThumbs[a].synchronousMetadata;
                var ftXMP = new XMPMeta(ftMeta.serialize());
                ftXMP.deleteProperty(XMPConst.NS_DC, 'title'); //delete old title
                ftXMP.appendArrayItem(XMPConst.NS_DC, 'title', ftTitle, 0, XMPConst.ALIAS_TO_ALT_TEXT); //write new title
                ftXMP.setQualifier(XMPConst.NS_DC, 'title[1]', 'http://www.w3.org/XML/1998/namespace', 'lang', 'x-default');
                var ftUpdatedPacket = ftXMP.serialize(XMPConst.SERIALIZE_OMIT_PACKET_WRAPPER | XMPConst.SERIALIZE_USE_COMPACT_FORMAT);
                ftThumbs[a].metadata = new Metadata(ftUpdatedPacket); //write to file
                }
            }
        }
    catch(e){
        alert(e + ' ' + e.line);
        }
    }

 

Stephen Marsh
Community Expert
Community Expert
November 30, 2023

This script will add the filename as Title metadata to all supported images in the top-level of the selected folder:

 

/* 
Add filename as Title metadata to images in top level of selected folder.jsx
v1.0 - 30th November 2023, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/edit-metadata-title-to-equal-filename/m-p/14266175
Based on
https://forums.adobe.com/thread/2584026
*/

#target photoshop;

var inputFolder = Folder.selectDialog("Select folder to add the filename as Title metadata");
if (inputFolder != null) {
    var fileList = inputFolder.getFiles(/\.(jpg|jpeg|tif|tiff|psd|psb|png|webp)$/i);
    for (var a in fileList) {
        var docName = fileList[a].name.replace(/\.[^\.]+$/, '');
        setTitle(fileList[a], docName);
    }
}

function setTitle(theFile, theValue) {
    if (!ExternalObject.AdobeXMPScript) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
    var xmpFile = new XMPFile(File(theFile).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
    var xmp = xmpFile.getXMP();
    xmp.deleteProperty(XMPConst.NS_DC, "title");
    xmp.setLocalizedText(XMPConst.NS_DC, "title", null, "x-default", theValue);
    if (xmpFile.canPutXMP(xmp)) {
        xmpFile.putXMP(xmp);
    }
    xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}

 

Stephen Marsh
Community Expert
Community Expert
November 30, 2023

The following script will add the filename to the title metadata field for an open doc in Photoshop:

 

#target photoshop

var docName = activeDocument.name.replace(/\.[^\.]+$/, '');
if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
xmp.deleteProperty(XMPConst.NS_DC, "title");
xmp.setProperty(XMPConst.NS_DC, "title", docName);
app.activeDocument.xmpMetadata.rawData = xmp.serialize();
Stephen Marsh
Community Expert
Community Expert
November 29, 2023

This is the Photoshop forum, there is a separate Bridge forum.

 

Both Photoshop and Bridge can add the filename as title metadata, with or without the extension, using a script (not a metadata template).

 

So it depends on workflow where this is preferred to be performed.

Participant
November 29, 2023

I would prefer Photoshop as I rarely use Bridge. Do you have a link to the script and usage instructions Stephen, ideally for batch processing rather than image by image?

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
November 30, 2023

I don't have a ready-made script for this task in Photoshop, I would need to write it.

 

Bridge is more common for this, I do have a Bridge script:

 

// https://imagesimple.wordpress.com/2011/08/24/cs5-filename-to-title-script/
#target bridge
   if( BridgeTalk.appName == "bridge" ) {
FT = MenuElement.create("command", "Add FileName to Title", "at the end of Tools");
}
FT.onSelect = function () {
   AddFilenameToTitle();
   }
function AddFilenameToTitle(){
var thumbs = app.document.selections;
if(!thumbs.length) return;
if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new
ExternalObject("lib:AdobeXMPScript");
for(var a in thumbs){
var selectedFile = thumbs[a].spec;
var Title = decodeURI(selectedFile.name).replace(/\.[^\.]+$/, '')
      var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN,
XMPConst.OPEN_FOR_UPDATE);
  var myXmp = myXmpFile.getXMP();
        myXmp.deleteProperty(XMPConst.NS_DC, "title");
        myXmp.appendArrayItem(XMPConst.NS_DC, "title", Title, 0,
XMPConst.ALIAS_TO_ALT_TEXT);
        myXmp.setQualifier(XMPConst.NS_DC, "title[1]",
"http://www.w3.org/XML/1998/namespace", "lang", "x-default");
        if (myXmpFile.canPutXMP(myXmp)) {
        myXmpFile.putXMP(myXmp);
         myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
         }
    }
}

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html