Last active
October 31, 2022 13:10
-
-
Save IsakViste/ff2fc41ad8495e1539447d640f305365 to your computer and use it in GitHub Desktop.
Script: Replace spaces in IPTC Headline tag of RAW Images with underscore
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/bash | |
cd "$PWD" | |
if [ -z "$1" ]; then | |
read -e -p "Image Extension: " EXTENSION | |
else | |
EXTENSION="$1" | |
fi | |
BACKUP_FOLDER=ORIGINALS_$(date +%Y%m%d-%H%M%S) | |
mkdir "$BACKUP_FOLDER" | |
for image in *.${EXTENSION}; do | |
name=`exiftool -s3 -iptc:Headline $image` | |
new_name=${name// /_} | |
if [ "$name" != "$new_name" ]; then | |
exiftool -iptc:Headline="$new_name" "$image" | |
original_file="${image}_original" | |
if [ -f "$original_file" ]; then | |
mv -vn "$original_file" "$BACKUP_FOLDER" | |
fi | |
echo "[$image]" | |
echo "$(exiftool -iptc:Headline "$image")" | |
echo "" | |
fi | |
done | |
if [ -z "$(ls -A $BACKUP_FOLDER)" ]; then | |
rmdir "$BACKUP_FOLDER" | |
fi |
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/bash | |
cd "$PWD" | |
if [ -z "$1" ]; then | |
read -e -p "Backup Folder: " TARGET_FOLDER | |
else | |
TARGET_FOLDER="$1" | |
fi | |
BACKUP_FOLDER=$(echo $TARGET_FOLDER | sed 's:/*$::') | |
cd "$BACKUP_FOLDER" | |
for image in *.*_original; do | |
new_name=${image/_original/} | |
mv -v "$image" "../$new_name" | |
echo "[$new_name] Headline: $(exiftool -s3 -iptc:Headline "../$new_name")" | |
echo "" | |
done | |
cd .. | |
if [ -z "$(ls -A $BACKUP_FOLDER)" ]; then | |
rmdir "$BACKUP_FOLDER" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment