Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
3

Edit metadata title to equal filename

Community Beginner ,
Nov 29, 2023 Nov 29, 2023

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.

 

Filename.jpg

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

Any guidance is gratefully accepted, Regards Paul

TOPICS
macOS
2.0K
Translate
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

correct answers 1 Correct answer

Community Expert , Nov 30, 2023 Nov 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
...
Translate
Adobe
Community Expert ,
Nov 29, 2023 Nov 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.

Translate
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
Community Beginner ,
Nov 29, 2023 Nov 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?

Translate
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
Community Expert ,
Nov 30, 2023 Nov 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

 

Translate
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 ,
Feb 12, 2025 Feb 12, 2025
LATEST

This is very helpful, thank you so much!!

Translate
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
Community Expert ,
Nov 30, 2023 Nov 30, 2023

 

The following script will add the filename as Title metadata without opening the selected file into Photoshop:

 

/*
Based on:
CS4 or later
https://www.ps-scripts.com/viewtopic.php?t=13493
*/

var selectFile = app.openDialog();
var selectedFile = File(selectFile);
var fileName = selectedFile.name.replace(/\.[^\.]+$/, '');

setDescription(selectedFile, fileName);

function setDescription(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);
}

 

 

Translate
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
Community Expert ,
Nov 30, 2023 Nov 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();
Translate
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
Community Expert ,
Nov 30, 2023 Nov 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);
}

 

Translate
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
LEGEND ,
Nov 30, 2023 Nov 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);
        }
    }

 

Translate
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
Community Expert ,
Nov 30, 2023 Nov 30, 2023

@AndrewPaulCooper 

 

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

Translate
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
Community Beginner ,
Dec 01, 2023 Dec 01, 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

Translate
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
Community Beginner ,
Dec 01, 2023 Dec 01, 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.

 

Screenshot 2023-12-01 at 10.29.25.jpg

 

Translate
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
LEGEND ,
Dec 01, 2023 Dec 01, 2023

I publish a script pack plus numerous utility scripts for Bridge and Photoshop. We see similar questions on here quite a bit and for custom solutions beyond the built-in features, scripting is invaluable.

Translate
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