News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Writting metadata to all images from a CSV file on Mac

Started by tedition, August 30, 2011, 07:59:26 AM

Previous topic - Next topic

tedition

I am trying to organize my photo library, I have thousands of photographs mostly CR2 and DNG images. I use and like Lightroom 3, I am not an advanced user of Lightroom. I am just getting introduced to AppleScripts, Automator and I found ExifTool by searching on Google. Very impressed on how much it can do. Thumbs up to Phil

Here is what I want to Achieve

During photoshoot i want to create a csv file on my iPhone or iPad that looks something like the following

FileName,Description,Comment,Keyword

and then when I come home I want to put all pictures from a photo shoot in a folder and have exiftool write metadata from the CSV file to pictures based on their filesnames.

After the above is done I will import these pics to my lightroom catalog and be able to use the metadata for organizing them.

Thank you for your kind assistance



Phil Harvey

This is simple.  From the Terminal, you would do the following:

1) cd "name of directory containing images and csv file"

2) exiftool -csv="name of csv file" .   <-- don't forget the "." -- it stands for the current directory

Just one minor point:  The first column of the .CSV file must be "SourceFile", not "FileName".  All other columns must be labelled according to the tag you want to write.

This should be fairly easy to build into an automator action or AppleScript if you want.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

tedition

Dear Phil,

Thank you for your prompt response, I am going to try this and post back with results.

Thank you again for creating this wonderful utility.

regards,
Tom

tedition

Works like a charm! Thank you.
I just have a question.

1. In order for the command to work I had to add "./" as prefix to each SourceFile. Is there anyway to avoid it.

Phil Harvey

#4
Good point.  I had missed this.

The SourceFile must be specified exactly the same as the file names on the command line, which will include the directory if a directory is specified.

To avoid the ".", specify the next level of directories, or the image file names directly on the command line (using wildcards is fine, ie. "*.jpg").

For the next exiftool release (8.64) I'll look into adding some logic so that "file.jpg" matches "./file.jpg" in the .CSV import.

- Phil

Edit: I am done adding the new logic to also key on canonical file path when looking for a matching SourceFile from the .CSV import.  I've tested it on OS X, and it seems to work well.  Look for this update in ExifTool 8.64 when it is released
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).


kskpatra

I am interesting to for that action.
Can you give me more instractions how to syntax the csv file.

I want the Caption for IPTC informations and i use this in the csv file
SourceFile,Caption
./_DSC6888.JPG,TestCaption1
./_DSC6889.JPG,TestCaption2


but nothing happend.

the syntax of the command prompt is
exiftool.exe -csv=csv_file.csv .

I have the exiftool.exe and the csv_file.csv and the pics in the same directory.
Thanks.

I just saw that the Title respond to Mac user and i use Windows
Can you help me with this?

Phil Harvey

#7
Sure I can help.  This should work, although I think you probably want to write a more common tag like IPTC:Caption-Abstract or XMP-dc:Description instead of XMP-acdsee:Caption.  It would help if you answered a few questions:

1) what messages do you get when you run the command (try using the -v2 option if you don't get any useful messages)?

2) what is your operating system and exiftool version number?

Here is what I get on my system here (a Mac):

> cat a.csv
SourceFile,Caption
./a.jpg,TestCaption1

> ls -l a.jpg
-rw-r--r--   1 phil  phil  4065022 Nov  3 13:02 a.jpg

> exiftool -ver
8.69

> exiftool -csv=a.csv a.jpg -v2
======== a.jpg
Writing XMP-acdsee:Caption
Rewriting a.jpg...
  Editing tags in: APP1 XMP
  Creating tags in: APP1 XMP
Creating APP1:
  Creating XMP
    + XMP-acdsee:Caption = 'TestCaption1'
JPEG DQT (130 bytes):
JPEG DHT (416 bytes):
JPEG SOF0:
JPEG SOS
    1 image files updated


- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

IXix

Hi Phil, thanks for exiftool, it looks really powerful but I'm struggling with csv operations. I want to use csv files to append keywords to a list of files but I think I'm having the same problem as kskpatra above. I'm using exiftool 8.69 on Windows 7.

My csv looks like this...
SourceFile,iptc:keywords
C:/Users/IX/Pictures/Photo/2007-12/0010.jpg,Test
C:/Users/IX/Pictures/Photo/2008-04/2008.04.15 16-51-01 - 15042008157.jpg,Test


and on the command line I use this...
exiftool.exe -csv=csvfile.csv

...but exiftool just prints out the usage instructions as if I hadn't passed any arguments. None of the files in the list have their metadata altered. Specifying -v2 doesn't provide any extra information either.

I thought it might be permissions related but this command works fine...
exiftool -iptc:keywords+=Test C:\Users\IX\Pictures\Photo\2007-12\0010.jpg

What could be going wrong? Any help would me much appreciated. If I can't get the csv command to work I could set up a batch/powershell script to do the files one by one but I've got around 3,500 images to process and I'd rather do it the smart way.

Thanks.

Phil Harvey

The confusion is because exiftool processes the files listed on the command line, and looks these up in the CSV database to get the tags to write.  So the command should be something like this:

exiftool -csv=csvfile.csv -r C:/Users/IX/Pictures/Photo

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

IXix

Quote from: Phil Harvey on November 12, 2011, 03:21:18 PM
The confusion is because exiftool processes the files listed on the command line, and looks these up in the CSV database to get the tags to write.
Ah, of course! Now you say it I can see it in your previous reply. Thankyou. At least this might help others who make the same stupid mistake.

Thanks again for the excellent tool.

Phil Harvey

I just noticed that you want to append the new keywords to the existing list.  For this, you should use -csv+=csvfile.csv.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

IXix

Quote from: Phil Harvey on November 12, 2011, 04:10:24 PM
I just noticed that you want to append the new keywords to the existing list.  For this, you should use -csv+=csvfile.csv
Heh, yeah. Took me a few minutes but I managed to figure that one out by myself. Hope springs eternal!

tdiaz

I'm another one of those "have thousands... " with a (soon to be) CSV file and will be doing a massive import into Aperture or Lightroom.  Both stuff that's been sorted/provided to me and what I'm doing myself, to get an absolute crapton of pictures into a referenced library structure.

What I have so far- a whole lot of directories and photos with a file as such that has three columns. Filename, Names and Descriptions. (See the image below)

I'd like the names to get into the keyword field and the description to get into the caption.

Will the comma's are going to cause issues,  perhaps I had need to export these enclosed those with quotes.. or figure out JSON? I've never heard of that format until reading it here.

I'll be renaming the Pic ID as SourceFile, Names as IPTC:keywords and Description as IPTC:caption and where I'm doing my own, start that way.  If I want to add an event name in there, it would be using some other field .. I just need to see what IPTC files Aperture puts stuff in I guess.. .

If I go to each directory in terminal and do this:
exiftool -csv+=2003XXX.csv -r .

What will happen with the file time/datestamps? Will they stay the same, or become [now] when it's done?


(I see that the example I chose has some incorrect entries.. )

Phil Harvey

If you have a question about the CSV format, try setting the tags for one file manually then use the exiftool -csv option to extract these tags. You will see that values with commas are quoted.

Use the -P option if you want to preserve the filesystem modification date/time.  If your filesystem supports a file creation date (standard OS X filesystems do), this is only preserved if you use the -overwrite_original_in_place option.  See FAQ 24 for details.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).