Skip to main content
Egis
Participating Frequently
April 25, 2017
Answered

export description from file info

  • April 25, 2017
  • 3 replies
  • 1924 views

Hi All,

Just wondering if there is an easy way to export description from image file info into one text file (or spreadsheet) eg doing batch or similar action? I would get 100 pics every week with captions embedded as description and would like to have all in one text file..

Cheers

Egis

This topic has been closed for replies.
Correct answer SuperMerlin

ThisPhotoshop script example will extract the filename and description to a csv file on the desktop, no files are opened.

It will prompt for the folder and extract details for jpg, psd or tif files.

#target photoshop;

app.bringToFront();

var inputFolder= Folder.selectDialog ("Please select folder to process");

if( inputFolder != null){

var fileList = inputFolder.getFiles(/\.(jpg|tif|psd)$/i);

var file = new File(Folder.desktop + "/Description info.csv");

file.open("e");

file.seek(0,2);

for(var a in fileList){

file.writeln( decodeURI(fileList.name)+ "," + getDescription(fileList));

}

file.close();

alert("Folder completed");

}

function getDescription(file){

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

  var xmpFile = new XMPFile( file.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ); 

  var xmp = xmpFile.getXMP(); 

         return  getArrayItems(xmp,XMPConst.NS_DC, "description");  

    } 

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

};

compupix
Known Participant
October 4, 2018

How does one extract both the Headline and the Description to a text file?

I tried using SuperMerlin's script; adding a headline function and a headline reference in the file.write line, but was unsuccessful. I only got the description.  I couldn't even get just the headline to work on its own.

I'd be willing to try the exiftool method if I knew how to reference both the headline and the description.

Thanks!

Stephen Marsh
Community Expert
Community Expert
October 4, 2018

I don’t have time to test if these various script options have an “out of the box” ability to export the fields you wish:

Prepression: Extracting Metadata to .CSV

The ExifTool command should just be a simple variation on the examples previously provided. Here is a detailed link to export out data using ExifTool and here is the same for importing.

So for a CSV on the Mac OS:

exiftool -csv -sourcefile -filename -headline -description -r '/Users/username/Desktop/in-folder' > '/Users/username/Desktop/metadata-out.csv'

Or perhaps a tab delimited file on the Mac OS:

exiftool -t -directory -filename -headline -description -r '/Users/username/Desktop/in-folder' > '/Users/username/Desktop/metadata-out.txt'

Legend
April 25, 2017

An alternate approach to the one presented by SuperMerlin would be using ExifTool.

This is a very powerful command line tool for "anything metadata". There are graphical frontends floating around, if I remember correctly. It can process individual files, but also whole folders. Extracting the Description is very straightforward, and it is about as easy to extract additional information in the same step.

The Exiftool home page is here.

Egis
EgisAuthor
Participating Frequently
April 25, 2017

Cheers guys, already tried SuperMerlin​ script and only changed csv to txt and got all out nice and easy.

will try maxwyss exiftool later on but look online and it sounds promising!

cheers!

Egis

Stephen Marsh
Community Expert
Community Expert
April 25, 2017

I’ll save you some time Egis:

exiftool -r -description -csv '/Users/currentuser/Desktop/Source Folder' > '/Users/currentuser/Desktop/exiftool-description-dump.csv'

This command will recursively scan a target folder “Source Folder” on the desktop of the logged in user (and any sub folders/files) and write out a .csv file titled “exiftool-description-dump.csv” to the desktop. It is possible to specify specific file type extensions for processing or to exclude specific named sub-folders under the top level folder.

This sample is for the Mac OS, on Windows you will need to change the straight single quotes ' to straight double quotes " and you will also need to change the file path to the expected Win OS path \ name.

The output will be something like this:

SourceFileDescription
/Users/currentuser/Desktop/Source Folder/myfile.jpgDescription Entry
/Users/currentuser/Desktop/Source Folder/another file.jpgAnother Different Description Entry

One can add the filename tag to the front of the code – then you could delete the SourceFile result column if that was not required:

exiftool -r -filename -description -csv

P.S.: Instead of using -csv one could use -T to write out a tab delimited file such as exiftool-description-dump.txt

SuperMerlin
SuperMerlinCorrect answer
Inspiring
April 25, 2017

ThisPhotoshop script example will extract the filename and description to a csv file on the desktop, no files are opened.

It will prompt for the folder and extract details for jpg, psd or tif files.

#target photoshop;

app.bringToFront();

var inputFolder= Folder.selectDialog ("Please select folder to process");

if( inputFolder != null){

var fileList = inputFolder.getFiles(/\.(jpg|tif|psd)$/i);

var file = new File(Folder.desktop + "/Description info.csv");

file.open("e");

file.seek(0,2);

for(var a in fileList){

file.writeln( decodeURI(fileList.name)+ "," + getDescription(fileList));

}

file.close();

alert("Folder completed");

}

function getDescription(file){

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

  var xmpFile = new XMPFile( file.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ); 

  var xmp = xmpFile.getXMP(); 

         return  getArrayItems(xmp,XMPConst.NS_DC, "description");  

    } 

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

};

Stephen Marsh
Community Expert
Community Expert
April 25, 2017

Cool, thanks SuperMerlin! Not knowing scripting, I would have thought that Photoshop would have to open up the file to get this info (which is where I would have presumed that Bridge was a better place to perform this task).

Egis
EgisAuthor
Participating Frequently
April 25, 2017

it took me a minute to figure it out Stephen_A_Marsh what's what but it's working fine, only I noticed that only works 10.7 and above, but works, thanks!