1
\$\begingroup\$

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
\$\endgroup\$
16
  • 1
    \$\begingroup\$ Possible duplicate of Rename a file based on whichever tag contains the earliest or oldest date? \$\endgroup\$
    – Michael C
    Commented Dec 4, 2017 at 16:58
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – StarGeek
    Commented Dec 4, 2017 at 17:29
  • 2
    \$\begingroup\$ 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 . \$\endgroup\$
    – StarGeek
    Commented Dec 4, 2017 at 18:17
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – StarGeek
    Commented Dec 4, 2017 at 18:21
  • 1
    \$\begingroup\$ 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 . \$\endgroup\$
    – StarGeek
    Commented Dec 4, 2017 at 18:24

1 Answer 1

1
\$\begingroup\$

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
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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