Skip to main content
Dave Swarthout
Known Participant
May 16, 2024
Answered

looking for a script that will write certain metadata to a text file

  • May 16, 2024
  • 2 replies
  • 2075 views

I would like to be able to write certain metadata for each image in a folder to a text file. I would like to see the filename, lens name, f/stop, shutter speed, focal length and ISO for each image.

I was a programmer at one time but that was a long time ago so I asked Gemini to write a Bridge script to access EXIF data.  Once that was working I planned to further customze the script output, again with the hhlep of Gemini or Bing AI but it produces an error each time I try to open Bridge with the new script installed. After several rewrites, some of which had the return statement in dfifferent locations, that statement always prodiuced an error. The Javascript iis below:
+++++++++++++++++++++++++++++

function extractEXIFDataToText(folderPath, filename) {
// Build the ExifTool command
var exifToolCmd = "C:\Users\&&&&&\Downloads\exiftool -csv -overwrite_original -quiet " + folderPath + " -Model -CreateDate -ExposureTime -FNumber -ISOSpeed -FocalLength -WhiteBalance -Caption-Abstract -Headline -Description -Keywords >> " + filename;

// Execute the ExifTool command
var result = execute(exifToolCmd);

// Check for errors
if (result != 0) {
alert("Error running ExifTool: " + result);
} else {
alert("EXIF data written to " + filename);
}
}

// Get folder path from user
var folderPath = Folder.selectDialog("Select Folder Containing Images");
if (folderPath == null) {
alert("No folder selected!");
return;
}

// Get output filename from user
var filename = prompt("Enter filename for output text file (e.g., exif_data.txt)");
if (filename == null || filename.length === 0) {
alert("Please enter a filename!");
return;
}

// Call the extractEXIFDataToText function
extractEXIFDataToText(folderPath, filename);

 

++++++++++++++++++++++++

Bridge complains that the return statement on line 20 is outside the function (or words to that effect).

Can anybody help? Thanks in advance.

This topic has been closed for replies.
Correct answer Stephen Marsh

Here is an example using more specific entries from your list of requirements:

 

exiftool -System:FileName -XMP-aux:LensInfo -XMP-aux:Lens -XMP-exifEX:LensModel -XMP-exifEX:LensMake -Composite:LensID -ExifIFD:ExposureTime -Composite:ShutterSpeed -ExifIFD:FocalLength -ExifIFD:ISO -csv 'OS specific/path to the/input folder' > 'OS specific/path to the output/metadata file.csv'

 

The -Composite: group tag entries are derived from other metadata entries, simply remove any redundant tags as I have attempted to provide some overlap/flexibility.

2 replies

Legend
May 16, 2024

Adobe's XMP scripting is a PITA, frankly. I have written numerous scripts to work with metadata and in general, once you figure out the syntax, EXIFTool is a lot more powerful.

And forget AI for programming. Garbage in, garbage out.

Stephen Marsh
Community Expert
Community Expert
May 16, 2024

@Dave Swarthout 

 

You can start with taking a look at the following scripts:

 

 

https://prepression.blogspot.com/2016/08/extracting-metadata-to-csv.html

 

Although Bridge is probably the best tool for this task, Photoshop can also do the job.

 

The easiest way to do this sort of thing is using ExifTool as it is far easier than scripting. The following code -r recurses into all subfolders under the root directory and and writes -all metadata to -csv file:

 

 

exiftool -r -all -csv 'OS specific/path to the/input folder' > 'OS specific/path to the output/metadata file.csv'

 

 

You would replace the -all flag with the specific metadata entries that you require.

 

Note: If you use Windows, replace the single-straight quotes for double-straight quotes around paths that contain spaces.

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
May 16, 2024

Here is an example using more specific entries from your list of requirements:

 

exiftool -System:FileName -XMP-aux:LensInfo -XMP-aux:Lens -XMP-exifEX:LensModel -XMP-exifEX:LensMake -Composite:LensID -ExifIFD:ExposureTime -Composite:ShutterSpeed -ExifIFD:FocalLength -ExifIFD:ISO -csv 'OS specific/path to the/input folder' > 'OS specific/path to the output/metadata file.csv'

 

The -Composite: group tag entries are derived from other metadata entries, simply remove any redundant tags as I have attempted to provide some overlap/flexibility.

Dave Swarthout
Known Participant
May 16, 2024

That is awesome! Thanks so much @Stephen Marsh 

I think a better approach for my needs given what you've told me about EXIFtool,  is to use Python to extract the data outside of either Photoshop or Bridge. EXIFtool is a beautiful app that I've used on occasion before but it's tricky to use it from the command prompt. You've spelled it all out for me.

Also, thanks for pointing me to those other resources and scripts. Iy'll take a while to digest everything LOL