Created
August 10, 2025 06:36
-
-
Save neo22s/c7b49b4f737ec5ab7a5129ac189cc77a to your computer and use it in GitHub Desktop.
Adds a 1-star rating (XMP:Rating=1) to all specified JPG/JPEG/DNG/RAW files (case-insensitive), only if not already rated.
This file contains hidden or 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 | |
# ===================================================== | |
# Script: rate.sh | |
# Purpose: Adds a 1-star rating (XMP:Rating=1) to all | |
# specified JPG/JPEG/DNG/RAW files (case-insensitive), | |
# only if not already rated. | |
# | |
# Usage: | |
# ./rate.sh IMG_1234.JPG IMG_1235.jpg | |
# | |
# Requires: | |
# - exiftool | |
# ===================================================== | |
shopt -s nocaseglob nullglob | |
RAW_EXTENSIONS=("CR3" "CR2" "ARW" "NEF" "RAF" "ORF" "RW2" "DNG") | |
if [ $# -eq 0 ]; then | |
echo "Usage: $0 <file1> <file2> ..." | |
exit 1 | |
fi | |
echo "🔧 Rating images..." | |
for input in "$@"; do | |
input=$(echo "$input" | xargs) # trim spaces | |
base="${input%.*}" | |
found_any=false | |
# Rate JPG/JPEG/DNG if exists and not already rated | |
for ext in jpg jpeg dng; do | |
for file in ./"$base".${ext}; do | |
if [[ -f "$file" ]]; then | |
exiftool -m -overwrite_original -quiet -if 'not $Rating or $Rating eq "0"' -Rating=1 "$file" | |
echo "✔️ Rated $(basename "$file")" | |
found_any=true | |
fi | |
done | |
done | |
# Rate RAW variants | |
for ext in "${RAW_EXTENSIONS[@]}"; do | |
for file in ./"$base".${ext}; do | |
if [[ -f "$file" ]]; then | |
exiftool -m -overwrite_original -quiet -if 'not $Rating or $Rating eq "0"' -Rating=1 "$file" | |
echo "✔️ Rated $(basename "$file")" | |
found_any=true | |
fi | |
done | |
done | |
if [ "$found_any" = false ]; then | |
echo "⚠️ No files found for base name: $base" | |
fi | |
done | |
echo "✅ Rating complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment