Skip to main content
SuperMacGuy
Known Participant
December 8, 2009
Answered

Script to add description and keywords to files from text file

  • December 8, 2009
  • 2 replies
  • 2504 views

Can anyone write something up for me? I will admit I cannot do it myself, I do not know Javascript.

I need to add keywords and a description to 1000's of images. I have a text file formatted as such for each 100 images. The script would need to ask for an input file (or I can hardcode the path into the script) and then apply to the current folder of images shown in bridge.

Text file example:

1000 - Bright Sunset Over City. (sun;city;sky;mountain;) .

1001 - Dawn Behind Mountain And Lake. (sun;mountain;water;sky;) .

1002 - Bright Red Sunset, Light Edged Clouds. (sun;sky;tree;clouds;) .

1003 - Tree Framing Sunset Over Bay. (tree;sun;lake;bay;) .

1004 - Sun Behind Gull On Pilings. (seagull;sun;sea;pilings;) .

images are named 1000.tif, 1001.tif, 1002.tif etc

Running on a Mac with CS3 and CS4.

Thanks,

Chris

This topic has been closed for replies.
Correct answer Paul Riggott

Many thanks David, I must read up more on these things, I have amended the script as you noted.

2 replies

Stephen Marsh
Community Expert
Community Expert
July 21, 2017

As I don’t know how to script, I like to use these old threads to help me to learn how to do the same thing with ExifTool:

The .CSV data would be formatted as follows:

SourceFile,Description,Subject

/PATH_to_IMAGE_DIRECTORY/1000.tif,1000 - Bright Sunset Over City,"sun,city,sky,mountain"

/PATH_to_IMAGE_DIRECTORY/1001.tif,1001 - Dawn Behind Mountain And Lake,"sun,mountain,water,sky"

/PATH_to_IMAGE_DIRECTORY/1002.tif,"1002 - Bright Red Sunset, Light Edged Clouds","sun,sky,tree,clouds"

This was an interesting case (line 4 and the multiple keywords), as one can’t use commas in a CSV to separate other data, so one has to enclose the unwanted text containing commas with quote marks.

Then to import, the following ExifTool command would be used:

exiftool -r -sep ', ' -csv='/PATH_to_CSV/input.csv' '/PATH_to_IMAGE_DIRECTORY'

This example is formatted on the Mac OS, minor modifications would be needed to run on Windows (most likely changing single straight quotes to double straight quotes and possibly vice versa with double quotes).

Paul Riggott
Inspiring
December 8, 2009

This should work with CS3 or CS4. Hope it works for you.

dfranzen_camera_raw
Adobe Employee
Adobe Employee
December 9, 2009

Hi Paul,

This is nice example, but your script incorrectly sets both dc:description and dc:subject as ordered arrays. Description should be an alt-text type property, and subject is an unordered array (or 'bag'). Some software might not tolerate the incorrect XMP data types.

Here's an example showing the wrong and write way to set these two properties using the XMP Script API:

// load the library
if (ExternalObject.AdobeXMPScript == undefined) {
    ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
}


var Desc = "Test Description";
var Keys = ["One","Two","Three"];


// The wrong way to set the Description. and Keywords...
var bogusXmp = new XMPMeta();
bogusXmp.appendArrayItem(XMPConst.NS_DC, "description", Desc, 0,XMPConst.ARRAY_IS_ORDERED);
for(var s in Keys){
      bogusXmp.appendArrayItem(XMPConst.NS_DC, "subject", Keys, 0,XMPConst.ARRAY_IS_ORDERED);
}
$.writeln( bogusXmp.dumpObject() );

// The correct way to set the Description and Keywords
var correctXmp = new XMPMeta();
correctXmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", Desc );
for(var s in Keys){
      correctXmp.appendArrayItem(XMPConst.NS_DC, "subject", Keys, 0,XMPConst.PROP_IS_ARRAY);
}
$.writeln( correctXmp.dumpObject() );

Thanks,

David

Paul Riggott
Paul RiggottCorrect answer
Inspiring
December 9, 2009

Many thanks David, I must read up more on these things, I have amended the script as you noted.