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

Photoshop Metadata automation

New Here ,
Sep 26, 2024 Sep 26, 2024

Copy link to clipboard

Copied

Is there a way to automate adding the current file name to the document title metadata? I have to do this to a couple hundred images, so it would be nice if it was automated versus having to do them manually.

 

Screenshot 2024-09-26 at 11.05.43 AM.png

Views

344

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 Expert ,
Sep 26, 2024 Sep 26, 2024

Copy link to clipboard

Copied

in the future, to find the best place to post your message, use the list here, https://community.adobe.com/

p.s. i don't think the adobe website, and forums in particular, are easy to navigate, so don't spend a lot of time searching that forum list. do your best and we'll move the post (like this one has already been moved) if it helps you get responses.



<"moved from cc desktop">

Votes

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
Community Expert ,
Sep 26, 2024 Sep 26, 2024

Copy link to clipboard

Copied

Although possible in Photoshop to directly batch edit metadata without opening each file, this is generally best performed in Adobe Bridge.

 

This has come up before and there are multiple scripts in the Photoshop and Bridge forums, or ExifTool commands etc. The forum or site search function should return these discussions with a suitable search term.

 

Here are some Bridge scripts:

 

 

// 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);
         }
    }
}

 

 

Or:

 

 

/**
* @@@BUILDINFO@@@ FilenametoTitle.jsx !Version! Tue Nov 26 2019 09:07:36 GMT-0500
*/
/*
Utility Pack Scripts created by David M. Converse ©2018-19

Writes filename to Title metadata field.

/* Modified 30 March 2020 by Stephen Marsh to retain original filename in full */

/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#target bridge

if (BridgeTalk.appName == 'bridge') {
    try {
        var FilenametoTitle = new Object; //id object for this script
        #include "prefsReader.jsxinc" //shared prefs read code

        //create menu
        if (useMenu == true) { //use Tools submenu
            if (MenuElement.find('utilPack') == null) { //submenu not yet created
                MenuElement.create('menu', 'Utility Script Pack', 'at the end of Tools', 'utilPack');
            }
            var ftCmd = MenuElement.create('command', 'Filename to Title', 'at the end of utilPack');
        }
        else { //do not use submenu
            var ftCmd = MenuElement.create('command', 'Filename to Title', 'at the end of Tools');
        }

        if (useCMenu == true) { //use contextual submenu
            if (MenuElement.find('cutilPack') == null) {
                MenuElement.create('menu', 'Utility Script Pack', 'after Thumbnail/Open', 'cutilPack');
            }
            var ftContCmd = MenuElement.create('command', 'Filename to Title', 'at the end of cutilPack'); //add to Contextual menu
        }
        else { //do not use contextual submenu
            var ftContCmd = MenuElement.create('command', 'Filename to Title', 'after Thumbnail/Open', this.menuID); //add to Contextual menu
        }
    }
    catch (e) {
        //alert(e + e.line);
    }
}

ftCmd.onSelect = function () {
    ftAddFilenameToTitle();
}

ftContCmd.onSelect = function () {
    ftAddFilenameToTitle();
}

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
            var ftTitle = ftThumbs[a].name; //get filename
            //remove filename after last dash character
            //to retain filename after dash, comment out lines 69-73
            //ftTitle = ftTitle.split('-');
            //if(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);
    }
}

 

 

Or:

 

 

// Filename to metadata title.jsx
// https://forums.adobe.com/message/3596812
#target bridge
   if( BridgeTalk.appName == "bridge" ) {
FT = MenuElement.create("command", "Add FileName to Description", "at the end of Tools");
}
FT.onSelect = function () {
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 FileName = decodeURI(selectedFile.name).replace(/\.[^\.]+$/, '')
      var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
  var myXmp = myXmpFile.getXMP();
var Desc=[];
var count =  myXmp.countArrayItems(XMPConst.NS_DC, "description");
for(var i = 1;i <= count;i++){
Desc.push(myXmp.getArrayItem(XMPConst.NS_DC, "description", i));
    }
Desc=Desc.toString() + " " + FileName;
        myXmp.deleteProperty(XMPConst.NS_DC, "description");
        myXmp.appendArrayItem(XMPConst.NS_DC, "description", Desc, 0, XMPConst.ALIAS_TO_ALT_TEXT);
        myXmp.setQualifier(XMPConst.NS_DC, "description[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

 

Votes

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
Community Expert ,
Sep 26, 2024 Sep 26, 2024

Copy link to clipboard

Copied

And here is a Photoshop script for root/top-level files in a 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);
}

 

Or this variation on the previous Photoshop script, where you can select multiple files rather than their parent folder:

 

/* 
Add filename as Title metadata to selected images.jsx
v1.0 - 27th September 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/photoshop-metadata-automation/td-p/14883408
Based on
https://community.adobe.com/t5/photoshop-ecosystem-discussions/edit-metadata-title-to-equal-filename/m-p/14266175
*/

#target photoshop;

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

/*
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);
}

 

Votes

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 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

Thanks Stephen, I tried this Bridge script you'd created from another post but I'm getting the error below. Am i doing something wrong? 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/edit-metadata-title-to-equal-filename/m-p/14268068#M768067

Screenshot 2024-09-27 at 10.02.17 AM.png

Votes

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
LEGEND ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

Specifically which script did you use? Did you save as PLAIN TEXT and not RTF?

Votes

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 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

I saved it as a .jsx file

Votes

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
LEGEND ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

But that first line is total garbage. That's not Javascript. It has to be plain text format with a .jsx extension.

Votes

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 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

This is the script I used

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 =
newExternalObject("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);
}
}}

Votes

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
LEGEND ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

You'll notice that Line 1 doesn't match Line 1 shown in that error message.

Votes

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
LEGEND ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

Oh and that script won't work for RAW files. It opens the file but for RAW, the data is stored in a second sidecar file.

Try one of the first two posted scripts, the second one is mine.

Votes

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
Community Expert ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

quote
image.png
By @Maximilliano25358244hf0u

 

What program did you use to save the code text? Please read my linked blogpost, if I need to update the instructions for edge cases such as yours I'm happy to do so:

 

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

 

Votes

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
Community Expert ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

LATEST

For the sake of completeness, here is an example of a command line for ExifTool:

 

exiftool -overwrite_original_in_place '-title<${filename;s/\.[^.]*$//}' -r '/Path/to/the folder containing the files/'

 

This command is formatted for the Mac, Windows would use " double straight quotes rather than ' single straight quotes.  After the -r and space, one can drag the root/top-level folder from the Mac Finder or Windows Explorer into the Terminal or CMD window to complete the path to the folder and press return/enter to execute. It is recommended that you work on a few duplicate files in a new folder for testing until you are comfortable.

 

Votes

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