1

I am looking for a way to use exiftool to extract the date of creation from the pictures in a directory and just in case they differ, use the earliest date. The application case is a concert that runs from 04.12.2017:20:00 until 05.12.2017:00:20. My agency want all pictures from the set to have the same day stamp. So it should say 04.12.2017 on all pictures. I guess there is a cleaver one-liner to do this. Is there?

Edit: As suggested in the comments, this has to be done by a script. This is the shell script I have so far.

#!/bin/tcsh -f


# remove Umlaute

exiftool -L -api "Filter=s/ä/ae/g" -TagsFromFile @ -all:all .
exiftool -L -api "Filter=s/ö/oe/g" -TagsFromFile @ -all:all .
exiftool -L -api "Filter=s/ü/ue/g" -TagsFromFile @ -all:all .


exiftool -L -api "Filter=s/Ä/Ae/g" -TagsFromFile @ -all:all .
exiftool -L -api "Filter=s/Ö/Oe/g" -TagsFromFile @ -all:all .
exiftool -L -api "Filter=s/Ü/Ue/g" -TagsFromFile @ -all:all .
exiftool -L -api "Filter=s/ß/ss/g" -TagsFromFile @ -all:all .

# extend caption by ", ":

exiftool '-caption-abstract<${caption-abstract}, ' .


#set date to earliest date in the set
exiftool -T -DateCreated .


# clean up
rm *.jpg_original

Edit 2:

This is the solution:

#!/bin/tcsh -f


# remove all Umlaute
exiftool -L -overwrite_original -api "Filter=s/ä/ae/g;s/ö/oe/g;s/ü/ue/g;s/Ä/Ae/g;s/Ö/Oe/g;s/Ü/Ue/g;s/ß/ss/g" -TagsFromFile @ -all:all .


# add ", " to the caption:

exiftool '-caption-abstract<${caption-abstract}, ' .

# set all dates to the earliest date
set earliest_date="`exiftool -DateCreated -fileorder DateCreated -q -s3 . | head -1`"
set latest_date="`exiftool -DateCreated -fileorder DateCreated -q -s3 . | tail -1`"

if ( "$earliest_date" == "$latest_date" ) then
   echo "checked date"
else
   echo "earliest date is $earliest_date and latest date is $latest_date"
   echo "setting DateCreated to $earliest_date and TimeCreated to unknown"
   exiftool -DateCreated=$earliest_date .
   exiftool -TimeCreated="00:00:00" .
endif
Stefan
  • 65
  • 6
  • 1
  • Have you already shot the job or is it upcoming later today where you are? – Michael C Dec 04 '17 at 17:01
  • 2
    This is something you would have to script. One pass to find the earliest date and then another to actually set all the file to that date. This can't be one-lined in exiftool as it only acts upon one file at a time and doesn't retain data from files it has already processed. – StarGeek Dec 04 '17 at 17:29
  • The job is done. But I am looking for solutions for the future. – Stefan Dec 04 '17 at 17:35
  • OK. I added the script I have so far. It is tcsh. Could you tell me how to do it with a script? Thanks! – Stefan Dec 04 '17 at 17:36
  • 2
    Started to work something up (scripting isn't my strong point) and I realized you weren't on Windows. I think I can give the basic idea (won't format properly in a comment like this, though). Run exiftool to get the earliest date. I think piping through head will give you the earliest value. Assign that to a variable. exiftool -DateCreated -fileorder DateCreated -q -s3 . | head -1 Then, take that and assign that to all the files exiftool -DateCreated =$VAR . – StarGeek Dec 04 '17 at 18:17
  • 2
    As an additional comment, you can combine all your Filter substitutions into one command. Use -api "Filter=s/ä/ae/g;s/ö/oe/g;s/ü/ue/g;s/Ä/Ae/g;s/Ö/Oe/g;s/Ü/Ue/g;s/ß/ss/g" When you want to add a new one, just add it on the end, separated with a semicolon. – StarGeek Dec 04 '17 at 18:21
  • 1
    Also, you can avoid the cleanup command by adding -overwrite_original to your commands. For example, exiftool -L -overwrite_original -api "Filter=s/ä/ae/g;s/ö/oe/g;s/ü/ue/g;s/Ä/Ae/g;s/Ö/Oe/g;s/Ü/Ue/g;s/ß/ss/g" -TagsFromFile @ -all:all . – StarGeek Dec 04 '17 at 18:24
  • Somehow the combined filters do not work. The mess around with the Umlaute. Seems to be a unicode problem. Probably bug in the version of exiftool. – Stefan Dec 04 '17 at 19:59
  • This is the result of applying the filters in one go: Sänger, Sängerin, – Stefan Dec 04 '17 at 20:24
  • Is that what shows up in Lightroom or output by exiftool? Is -L part of the command? Without getting too deep into the subject, ä is the two byte sequence that makes up ä. – StarGeek Dec 04 '17 at 21:45
  • I see this when looking at the file information that MacOS provides after applying the combined filter. When using the filter for one Umlaut at the time, everything is fine. – Stefan Dec 05 '17 at 07:07
  • OK. It works. I had to write it myself. I guess I copied some invisible stuff when I copied your code from here with copy&paste. I tried to replace the Umlaute but this was not sufficient. I had to write the line from scratch. Now it works! – Stefan Dec 05 '17 at 07:50
  • You may add my edit as the solution so that I could give you credit. Someone should remove the duplicate tag at the beginning. Thanks for everything! – Stefan Dec 05 '17 at 07:56
  • If the posted solution works (as I assume it does), one of you should post it as an answer. – Joe Dec 05 '17 at 22:44
  • 1
    @Stefan, Thanks but I'm not worried about the credit. More important that you get things working how you want. Also, make sure and check out the exiftool forums if you have other exiftool related questions. – StarGeek Dec 08 '17 at 15:25

1 Answers1

1

This is the solution. It also contains imprivements to the original script.

#!/bin/tcsh -f


# remove all Umlaute
exiftool -L -overwrite_original -api "Filter=s/ä/ae/g;s/ö/oe/g;s/ü/ue/g;s/Ä/Ae/g;s/Ö/Oe/g;s/Ü/Ue/g;s/ß/ss/g" -TagsFromFile @ -all:all .


# add ", " to the caption:

exiftool '-caption-abstract<${caption-abstract}, ' .

# set all dates to the earliest date
set earliest_date="`exiftool -DateCreated -fileorder DateCreated -q -s3 . | head -1`"
set latest_date="`exiftool -DateCreated -fileorder DateCreated -q -s3 . | tail -1`"

if ( "$earliest_date" == "$latest_date" ) then
   echo "checked date"
else
   echo "earliest date is $earliest_date and latest date is $latest_date"
   echo "setting DateCreated to $earliest_date and TimeCreated to unknown"
   exiftool -DateCreated=$earliest_date .
   exiftool -TimeCreated="00:00:00" .
endif
Stefan
  • 65
  • 6