Extract part of filename and write to "Title" field in IPTC

New Here ,
Feb 21, 2018 Feb 21, 2018

Copy link to clipboard

Copied

I have a series of files that follow the naming convention shown below.

RED = Date and is always 6 digits

BLUE = This string is a product code which can contain up to 3 letters followed by up to 6 digits, separated by an underscore

What is the best way to extract what is in blue and write this to the Title field in IPTC?

032917_R_1234_Description.tif

Thank you,

Morgan

TOPICS
Scripting

Views

2.1K

Likes

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

correct answers 1 Correct Answer

Guide , Feb 21, 2018 Feb 21, 2018
Try this for selected documents...#target bridge      if( BridgeTalk.appName == "bridge" ) {  addTitle= MenuElement.create("command", "Add Title", "at the end of Tools");}addTitle.onSelect  = function () {  var thumbs = app.document.selections; if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");for(var a =0;a<thumbs.length;a++){var selectedFile =  new Thumbnail(thumbs); Title=decodeURI(selectedFile.spec.name).split("_");if(Ti...

Likes

Translate

Translate
Guide ,
Feb 21, 2018 Feb 21, 2018

Copy link to clipboard

Copied

Try this for selected documents...

#target bridge  

   if( BridgeTalk.appName == "bridge" ) { 

addTitle= MenuElement.create("command", "Add Title", "at the end of Tools");

}

addTitle.onSelect  = function () { 

var thumbs = app.document.selections;

if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

for(var a =0;a<thumbs.length;a++){

var selectedFile =  new Thumbnail(thumbs);

Title=decodeURI(selectedFile.spec.name).split("_");

if(Title.length <3) continue;

newTitle =(Title[1] +"_"+Title[2]);

app.synchronousMode = true;

var xmp = new XMPMeta(selectedFile.synchronousMetadata.serialize());

xmp.setLocalizedText( XMPConst.NS_DC, "title", null, "en-US", newTitle);

var newPacket = xmp.serialize(XMPConst.SERIALIZE_USE_COMPACT_FORMAT);

selectedFile.metadata = new Metadata(newPacket);

}

ExternalObject.AdobeXMPScript.unload();

ExternalObject.AdobeXMPScript = undefined;

};

Likes

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 Professional ,
Feb 21, 2018 Feb 21, 2018

Copy link to clipboard

Copied

I like these questions as they are a good way for me to practice regular expressions and ExifTool commands etc.

Here is an ExifTool solution that uses a regular expression based search/replace to write the required part of the filename to the title metadata. Note that any content that already exists in the title field will be replaced:

exiftool -r '-title<${filename;s/(^\d+?_)(.+?_\d+?)(_.+)/$2/}' '/path/to file/or main top level folder/here'

This command is from the Mac OS, for Win OS simply change the straight single ' quotes to straight double " quotes if the path to the top level folder has a word space in it. Further commands can be added to only process specific file formats and or to ignore specific folders under the main top level folder. Further commands can be added to overwrite the original files rather than making a backup _original duplicate copy.

Likes

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 Professional ,
Feb 21, 2018 Feb 21, 2018

Copy link to clipboard

Copied

Here is a Bridge script that I modifed to use the same regular expression capture group find/replace as used in the previous ExifTool example. I personally find it easier to work with regular expressions to modify a script, as I am only a beginner with JavaScript/ExtendScript so the methods used by SuperMerlin are not as clear to me as RegEx. Note that any content that already exists in the title field will be replaced:

// https://imagesimple.wordpress.com/2011/08/24/cs5-filename-to-title-script/

// https://forums.adobe.com/thread/2455681

// Input filename: 032917_R_1234_Description.tif

// Output Title metadata: R_1234

#target bridge

  if( BridgeTalk.appName == "bridge" ) {

FT = MenuElement.create("command", "Add Specific Filename RegEx Pattern 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.spec;

var Title = decodeURI(selectedFile.name).replace(/(^\d+?_)(.+?_\d+?)(_.+)/,'$2')

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

        }

    }

}

Prepression: Downloading and Installing Adobe Scripts

Likes

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 ,
Feb 22, 2018 Feb 22, 2018

Copy link to clipboard

Copied

Hi Stephen,

Thank you so much for your quick response and solution! It worked!!!!

I am not a programmer of any kind but spend a lot of time looking at how I can leverage existing data for DAM solutions.

Thanks again,

Morgan

Likes

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 Professional ,
Feb 22, 2018 Feb 22, 2018

Copy link to clipboard

Copied

Hi Morgan, thank you for the reply and for providing me with an opportunity to practice and learn.

Likes

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 ,
Feb 22, 2018 Feb 22, 2018

Copy link to clipboard

Copied

Hi Stephen,

You might already know of this site but I tried using this to try and understand regex syntax.

https://regex101.com/

Thanks,

Morgan

Likes

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 Professional ,
Feb 22, 2018 Feb 22, 2018

Copy link to clipboard

Copied

LATEST

Hi Morgan, yes, that is one of my main “go to” sites!

I also like:

RegExr: Learn, Build, & Test RegEx

Regex Tester and Debugger Online - Javascript, PCRE, PHP  

As you may know, there are multiple valid regular expressions that lead to the same result, some more concise/verbose than others and some more robust than others.

Likes

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