Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Add a missing timestamp to files with exiftool # This happened when I had multiple photos without datetimeoriginal timestamp set. It broke my gallery. # Little script adds timestamps to files that misses it but leaves it in files that has it already set. # How to use it # Place it in the folder where you have the photos/other files # chmod +x …
#!/bin/bash
# Add a missing timestamp to files with exiftool
# This happened when I had multiple photos without datetimeoriginal timestamp set. It broke my gallery.
# Little script adds timestamps to files that misses it but leaves it in files that has it already set.
# How to use it
# Place it in the folder where you have the photos/other files
# chmod +x efif-add-missing-ts.sh
# ./efif-add-missing-ts.sh . "2017:09:22 22:25:00"
# It creates copies of the original files (they can be removed with rm -rf *_original )
# NOTICE:
# The first argument should signify the location of the files but the script needs to be still in the same folder as the files are.
if [[ $1 == "" ]]; then
echo "Specify location where images or movies"
elif [[ $2 == "" ]]; then
echo "Specify new timestamp \"2012:03:14 12:25:00\""
fi
FILES_PATH=$1
FILES=$(ls $FILES_PATH)
NEW_TS=$2
for FILE in $FILES; do
echo "File: $FILE"
OUT=$(exiftool -q -if '(not $datetimeoriginal or ($datetimeoriginal eq "0000:00:00 00:00:00"))' -common $FILE)
if [[ "$OUT" != "" ]]; then
echo "Changing dates of $FILE to $NEW_TS"
exiftool -AllDates="$NEW_TS" $FILE
else
echo "File $FILE already has timestamp set"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment