--- /dev/null
+#!/bin/sh
+set -e
+
+num=1
+
+if [ -n "$DEBUG" ]; then
+ PREFIX=echo
+fi
+
+for f in *.JPG *.jpg; do
+ [ -f "$f" ] || continue
+ title=`exiv2 pr -Pv -gXmp.photoshop.Headline "$f"` || title=''
+ newname=`printf "%03i" $num`
+ if [ -n "$title" ]; then
+ newname="$newname - $title"
+ fi
+ newname="$newname.jpg"
+ if [ -e "$newname" ]; then
+ echo "Error: new name $newname for $f already exists, aborting" >&2
+ exit 1
+ fi
+ $PREFIX mv "$f" "$newname"
+ num=$((num+1))
+done