Copy link to clipboard
Copied
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
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
...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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);
}
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.