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

copy filename to iptc description

Guest
May 06, 2010 May 06, 2010

Copy link to clipboard

Copied

Hello,

I need to create a process of copying the filename of a tiff to the description in that same file's iptc. Ideally i'd like to be able to drop the script in to an Apple Automator process, but that would be a luxury. There's also an extra catch: i need the script to replace "=" with ":" and to add a prefix, for example "CMS:"

Here's an example:

input

filename: 8737=6.tif

description:

output

filename: 8737=6.tif

description: CMS:8737:6

It seems a faily basic process but i don't know where to start with this scripting business... Any help or advise would be much appreciated! Perhaps you know of a really similar one that i can modify??

Lewis

TOPICS
Scripting

Views

13.0K

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

Valorous Hero , May 06, 2010 May 06, 2010

Yet another version..


#target bridge  
   if( BridgeTalk.appName == "bridge" ) { 
FileNameToDesc = MenuElement.create("command", "Add FileName to Description", "at the end of Thumbnail");
}
FileNameToDesc.onSelect = function () {
   updateFileName();
   }
     
function updateFileName(){
loadXMPLib();
var Prefix = "CMS:";
var sels = app.document.selections;
for(var a in sels){
var thumb = new Thumbnail(sels);
   if(thumb.hasMetadata){
      var selectedFile = thumb.spec;   
      var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);      
      var myXmp = myXmpFile.getXMP();   
      var Name = decodeURI(sels
.name).replace(/\.[^\.]+$/, '');
        Name = Prefix + Name.replace(/\=/g,':');
      myXmp.deleteProperty(XMPConst.NS_DC, "description");
      myXmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default",Name );
      if (myXmpFile.canPutXMP(myXmp)) {
    myXmpFile.putXMP(myXmp);
         myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
         }
      }
}
unloadXMPLib();
}
function loadXMPLib(){
if (ExternalObject.AdobeXMPScript == undefined) {
    ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
}
}
function unloadXMPLib(){
   if( ExternalObject.AdobeXMPScript ) {
      try{
         ExternalObject.AdobeXMPScript.unload();
         ExternalObject.AdobeXMPScript = undefined;
      }catch (e){ }
   }
}

Votes

Translate

Translate
Community Expert ,
Jul 03, 2015 Jul 03, 2015

Copy link to clipboard

Copied

Philip Cord‌ & Carl. The reason you're getting the undefined is that there is no item in the XML file that makes up the XMP metadate for description until something is added. You need to check to see if there is an entry for that field then add to new information. You can see the difference between the before and after in this screen shot of the same raw data from the same file. I added some "555" to the description.

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 Beginner ,
Jul 05, 2015 Jul 05, 2015

Copy link to clipboard

Copied

Yep that worked, all I have to do is run the script twice, second time overwrites the undefined-part.

BIG THANK YOU guys!

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 Beginner ,
Jul 09, 2015 Jul 09, 2015

Copy link to clipboard

Copied

I just noticed that the script adds a "space" (" ") before the filename, is this an easy thing to fix?

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 ,
Jul 09, 2015 Jul 09, 2015

Copy link to clipboard

Copied

Rather than this line:

xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default",desc + " " +Name );

Replace it with these lines:

if(!desc || desc ==''){xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default",Name )}

else{xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default",desc + " " +Name )};

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 Beginner ,
Jul 09, 2015 Jul 09, 2015

Copy link to clipboard

Copied

Thanks, worked like a charm!

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
Participant ,
May 10, 2019 May 10, 2019

Copy link to clipboard

Copied

I would like to stuff the following information into the description:

{old description} + “ “ + {file name sans extension} + “ “ + {date created}

Using the indicated “Correct Answer by Paul Riggott on May 6, 2010 8:37 AM”

I’ve been able to stuff the file name sans extension into the description. I haven’t been able to add the old description and original creation date.

Thanks!

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
Guide ,
May 11, 2019 May 11, 2019

Copy link to clipboard

Copied

#target bridge;

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

updateDesc = MenuElement.create("command", "Update Desc", "at the end of Tools");

}

updateDesc.onSelect  = function () { 

var thumbs = app.document.selections;

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

for(var a in thumbs){

updateThumb(thumbs);

}

function updateThumb(selectedFile){

desc = '';

function getArrayItems(xmp,ns, prop){ 

var arrItem=[]; 

try{ 

var items = xmp.countArrayItems(ns, prop); 

for(var i = 1;i <= items;i++){ 

arrItem.push(xmp.getArrayItem(ns, prop, i)); 

     } 

return arrItem.toString(); 

}catch(e){alert(e +" Line: "+ e.line);} 

};

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

if(xmp.doesPropertyExist(XMPConst.NS_DC, "description")){

    desc = getArrayItems(xmp,XMPConst.NS_DC, "description").toString();

    }

desc += " " + decodeURI(selectedFile.name);

xmp.deleteProperty(XMPConst.NS_DC, "description");

if(xmp.doesPropertyExist(XMPConst.NS_XMP, "CreateDate")){

    var createDate = xmp.getProperty(XMPConst.NS_XMP, "CreateDate").toString();

    desc += " " + createDate;

    }

xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", desc);

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

selectedFile.metadata = new Metadata(newPacket);

    }

};

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
Participant ,
May 11, 2019 May 11, 2019

Copy link to clipboard

Copied

Thanks SuperMerlin.

That preserves the old description and adds the full file name and the creation time. Is it possible to add the file name without the extension and the creation date only.

Current output:

... 1823-017.jpg 2019-04-07T08:47:28.00

Desired output:

... 1823-017 2019-04-07

Even better would be to format the date as mm-dd-yyyy.

Thanks!

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
Guide ,
May 11, 2019 May 11, 2019

Copy link to clipboard

Copied

#target bridge;

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

updateDesc = MenuElement.create("command", "Update Desc", "at the end of Tools");

}

updateDesc.onSelect  = function () { 

var thumbs = app.document.selections;

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

for(var a in thumbs){

updateThumb(thumbs);

}

function updateThumb(selectedFile){

desc = '';

function getArrayItems(xmp,ns, prop){ 

var arrItem=[]; 

try{ 

var items = xmp.countArrayItems(ns, prop); 

for(var i = 1;i <= items;i++){ 

arrItem.push(xmp.getArrayItem(ns, prop, i)); 

     } 

return arrItem.toString(); 

}catch(e){alert(e +" Line: "+ e.line);} 

};

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

if(xmp.doesPropertyExist(XMPConst.NS_DC, "description")){

    desc = getArrayItems(xmp,XMPConst.NS_DC, "description").toString();

    }

desc += " " + decodeURI(selectedFile.name).replace(/\.[^\.]+$/, '');

xmp.deleteProperty(XMPConst.NS_DC, "description");

if(xmp.doesPropertyExist(XMPConst.NS_XMP, "CreateDate")){

    var cD =xmp.getProperty(XMPConst.NS_XMP, "CreateDate").toString().match(/(^\d{4})-(\d{2})-(\d{2})(.+)/);

    desc += " " + cD[2]+"-"+cD[3]+"-"+cD[1];

    }

xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", desc);

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

selectedFile.metadata = new Metadata(newPacket);

    }

};

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
Participant ,
May 11, 2019 May 11, 2019

Copy link to clipboard

Copied

Thanks SuperMerlin!

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 ,
May 12, 2019 May 12, 2019

Copy link to clipboard

Copied

I had fun replicating this request in ExifTool:

exiftool '-MWG:Description<$MWG:Description ${filename;s/\.[^.]*$//}' -execute '-MWG:Description<$MWG:Description ${XMP-xmp:CreateDate;s/(^\d{4}):(\d{2}):(\d{2})(.+)/$2-$3-$1/}' -common_args 'pathtoFILEorFOLDER'

I used the Metadata Working Group (MWG) "Description" tag so that the XMP Description tag, legacy IPTC Description tag and the IFD0 Description tag would all be updated/synced at the same time.

(formatted for the Mac, Windows would use straight double quotes)

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 ,
Jun 17, 2019 Jun 17, 2019

Copy link to clipboard

Copied

I added "Exiftool" to my terminal. Can i just copy this below to the terminal line in order to copy "filename: to the description:

exiftool '-MWG:Description<$MWG:Description ${filename;s/\.[^.]*$//}' -execute '-MWG:Description<$MWG:Description ${XMP-xmp:CreateDate;s/(^\d{4}):(\d{2}):(\d{2})(.+)/$2-$3-$1/}'-common_args 'pathtoFILEorFOLDER'

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 ,
Jun 17, 2019 Jun 17, 2019

Copy link to clipboard

Copied

Not the last argument, which is the path to the file or folder of files to process.

exiftool '-MWG:Description<$MWG:Description ${filename;s/\.[^.]*$//}' -execute '-MWG:Description<$MWG:Description ${XMP-xmp:CreateDate;s/(^\d{4}):(\d{2}):(\d{2})(.+)/$2-$3-$1/}'-common_args .

So the code above can be copied/pasted into Terminal, make sure that there is a space at the end as indicated above with the underscore.

Be careful when pasting that straight quotes don't become curly!

Then you can drag-n-drop a file, multiple files or a top-level folder into the Terminal window to complete the command and then press return.

The above code will create backup files, if you have made separate backups you could then add the -overwrite_original argument (work on dupes until you are sure all is working).

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 ,
Jun 17, 2019 Jun 17, 2019

Copy link to clipboard

Copied

I would like Adobe Bridge to copy the "Filename" to "Headline" and "Description". I am using Visual Studio Code. I am not a coder in any way. Is there someone who can give me the coding and run threw how to input into Visual Studio Code and save it to Bridge startup scripts. Thanks

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 ,
Jun 17, 2019 Jun 17, 2019

Copy link to clipboard

Copied

This is what I got when I tried to save to Bridge startup scripts.

Image.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
Community Expert ,
Jun 17, 2019 Jun 17, 2019

Copy link to clipboard

Copied

I can’t see the full error code, it’s truncated. Save to the desktop or some other easy to access location with write permissions, then move the file to the startup scripts folder.

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 ,
Jun 17, 2019 Jun 17, 2019

Copy link to clipboard

Copied

Morgan Howarth

Morgan Howarth Photography

[Personal info removed by Mod]

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 ,
Jun 18, 2019 Jun 18, 2019

Copy link to clipboard

Copied

We are community volunteers, not Adobe employees. I'm not sure if Adobe has official support for scripting or not.

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 ,
Jun 18, 2019 Jun 18, 2019

Copy link to clipboard

Copied

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 ,
Jul 19, 2019 Jul 19, 2019

Copy link to clipboard

Copied

LATEST

VSC is still a bit problematic. I am in process of switching from ESTK but losing the Object Model Viewer is a big problem.

As for writing filename to XMP, I have a script in my soon-to-be-updated Utility Script Pack which does this. The meat of the script is below:

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.name; //get filename

            //remove filename after last dash character

            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.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.metadata = new Metadata(ftUpdatedPacket); //write to file

            }

        }

    catch(e){

        //alert(e + e.line);

        }

    }

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 ,
Jun 17, 2019 Jun 17, 2019

Copy link to clipboard

Copied

Adobe have moved on from ESTK with a plug-in for MSVS, however you can just use any plain text editor such as TextWrangler on Mac or NotePad on Win (using an IDE is not really necessary).

Just copy/paste the source code and save the plain text file with a .jsx filename extension ensuring that the editor does not force the naming to .jsx.txt with a doublue extension, it should be only .jsx

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