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

Batch replace characters in metadata Title

Community Beginner ,
Nov 02, 2024 Nov 02, 2024

Hello Community. 

I am looking for some help. I have managed to add Filename to Title in the IPTC Core metadata of a bulk set of images. However the file name brought across characters I want to remove.

E.g

Filename: Amika Maak_.jpg

Title: Amika Maak_

I want to remove the _ underscore so that I can use it as a caption in InDesign. 

 

How can I bacth edit Titles in metadata to remove unwanted characters?

TOPICS
Batch , Metadata , Problem or error , Scripting
254
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 02, 2024 Nov 02, 2024

I can't take credit for this script, the author is unknown, however, I believe that it was probably Paul Riggott:

 

#target bridge

if (BridgeTalk.appName == "bridge") {
    ReplaceTitle = new MenuElement("command", "Find and Replace in Title", "at the end of tools");
}

ReplaceTitle.onSelect = function () {
    var win = new Window('dialog', 'Find & Replace');
    g = win.graphics;
    //var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);
    //g.backgroundColor = myBrush;
...
Translate
Community Expert ,
Nov 02, 2024 Nov 02, 2024

I can't take credit for this script, the author is unknown, however, I believe that it was probably Paul Riggott:

 

#target bridge

if (BridgeTalk.appName == "bridge") {
    ReplaceTitle = new MenuElement("command", "Find and Replace in Title", "at the end of tools");
}

ReplaceTitle.onSelect = function () {
    var win = new Window('dialog', 'Find & Replace');
    g = win.graphics;
    //var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);
    //g.backgroundColor = myBrush;
    win.orientation = 'column';
    win.p1 = win.add("panel", undefined, undefined, { borderStyle: "black" });
    win.p1.preferredSize = [380, 100];
    win.g1 = win.p1.add('group');
    win.g1.orientation = "row";
    win.title = win.g1.add('statictext', undefined, 'Title Editor');
    win.title.alignment = "fill";
    var g = win.title.graphics;
    //g.font = ScriptUI.newFont("Georgia", "BOLDITALIC", 22);
    win.p6 = win.p1.add("panel", undefined, undefined, { borderStyle: "black" }); //Replace
    win.p6.preferredSize = [380, 100];
    win.g600 = win.p6.add('group');
    win.g600.orientation = "row";
    win.g600.alignment = 'fill';
    win.g600.st1 = win.g600.add('statictext', undefined, 'Find');
    win.g600.st1.preferredSize = [75, 20];
    win.g600.et1 = win.g600.add('edittext');
    win.g600.et1.preferredSize = [200, 20];
    win.g610 = win.p6.add('group');
    win.g610.orientation = "row";
    win.g610.alignment = 'fill';
    win.g610.st1 = win.g610.add('statictext', undefined, 'Replace');
    win.g610.st1.helpTip = "Leave this field blank if you want to remove the characters";
    win.g610.st1.preferredSize = [75, 20];
    win.g610.et1 = win.g610.add('edittext');
    win.g610.et1.preferredSize = [200, 20];
    win.g620 = win.p6.add('group');
    win.g620.orientation = "row";
    win.g620.alignment = 'fill';
    win.g620.cb1 = win.g620.add('checkbox', undefined, 'Global');
    win.g620.cb1.helpTip = "Replace all occurrences of";
    win.g620.cb2 = win.g620.add('checkbox', undefined, 'Case Insensitive');
    win.g620.cb2.value = true;
    win.g1000 = win.p1.add('group');
    win.g1000.orientation = "row";
    win.g1000.alignment = 'center';
    win.g1000.bu1 = win.g1000.add('button', undefined, 'Process');
    win.g1000.bu1.preferredSize = [170, 30];
    win.g1000.bu2 = win.g1000.add('button', undefined, 'Cancel');
    win.g1000.bu2.preferredSize = [170, 30];
    win.g1000.bu1.onClick = function () {
        if (win.g600.et1.text == '') {
            alert("No replace value has been entered!");
            return;
        }
        win.close(0);
        var sels = app.document.selections;
        for (var a in sels) {
            var thumb = sels[a];
            md = thumb.synchronousMetadata;
            if (win.g620.cb1.value && !win.g620.cb2.value) var patt = new RegExp(win.g600.et1.text.toString(), "g");
            if (!win.g620.cb1.value && win.g620.cb2.value) var patt = new RegExp(win.g600.et1.text.toString(), "i");
            if (win.g620.cb1.value && win.g620.cb2.value) var patt = new RegExp(win.g600.et1.text.toString(), "gi");
            if (!win.g620.cb1.value && !win.g620.cb2.value) var patt = new RegExp(win.g600.et1.text.toString());
            md.namespace = "http://purl.org/dc/elements/1.1/";
            var Caption = md.title ? md.title[0] : "";
            if (Caption == "") continue;
            var result = patt.test(Caption.toString());
            if (result == true) {
                var newCaption = Caption.replace(patt, win.g610.et1.text.toString());
                setTitle(sels[a].spec, newCaption);
            }
        }
    }
    win.show();
    function setTitle(file, Caption) {
        if (!ExternalObject.AdobeXMPScript) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
        var xmpf = new XMPFile(File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
        var xmp = xmpf.getXMP();
        xmp.deleteProperty(XMPConst.NS_DC, "title");
        xmp.setLocalizedText(XMPConst.NS_DC, "title", null, "x-default", Caption);
        if (xmpf.canPutXMP(xmp)) {
            xmpf.putXMP(xmp);
        }
        xmpf.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
Community Beginner ,
Nov 02, 2024 Nov 02, 2024

Brilliant thank you this worked like a charm. 

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 03, 2024 Nov 03, 2024
LATEST
quote

Brilliant thank you this worked like a charm. 


By @Ethereal_personality98BC

 

You're welcome!

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