Created
September 15, 2015 06:00
-
-
Save naupaka/d994a91361b035ba8e96 to your computer and use it in GitHub Desktop.
zsh script to pull a date string from a parent directory and write it into an image file's EXIF metadata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# Script to add back in missing EXIF creation data metadata using | |
# exiftool, based on parent folder (which contains date information) | |
# Naupaka Zimmerman | |
# naupaka at gmail.com | |
# September 14, 2015 | |
# Code is licensed CC-0 | |
# Set file incrementer | |
FILENUM=1 | |
# Save original argument delimiter variable to value | |
SAVEIFS=$IFS | |
# Change argument delimiter to end-of-line (no spaces) | |
IFS=$(echo -en "\n\b") | |
# Loop through all files in hard-coded image directory of choice | |
# extract the YYYY-MM-DD date string from the parent folder | |
# parse it to remove other stuff and newlines and save to a variable | |
# If image file has 'research' keyword tag and doesn't have a creation | |
# date set yet, then set it based on the parsed string | |
for file in $(ls -d1 /Users/naupaka/Pictures/2006/2006-07-30/*) | |
do | |
echo "$FILENUM processing $file" | |
DATEMOD=$(echo "$file" | grep -o '\/\d\d\d\d-\d\d-\d\d\/' | sed s@\/@@g | sed s/\-/\:/g | sed s/\n//g) | |
DATETIMEMOD=$(echo -n "$DATEMOD 12:00:00") | |
exiftool -datetimeoriginal=$DATETIMEMOD -if '$keywords =~ /research/' -if 'not $datetimeoriginal' "$file" | |
FILENUM=$((FILENUM+1)) | |
done | |
# Set the argument delimiter back to what it was when we started | |
IFS=$SAVEIFS | |
# to remove all original unmodified files (exiftool makes copies before modifying) | |
# rm -rv ~/Pictures/**/*original |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment