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
  • 1
  • 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 4 '17 at 17:29
  • 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 4 '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 4 '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 4 '17 at 18:24
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.