-
Notifications
You must be signed in to change notification settings - Fork 0
/
jarv_photo_renamer.sh
executable file
·72 lines (57 loc) · 1.71 KB
/
jarv_photo_renamer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh
#Automagic Photo renamer
#JMF 2016 - based on prior Bash scripts + my cluster Gaussian job launcher (!)
#Bash is a stranger in an open car...
#Get Options
#Defaults
Photographer="JarvistMooreFrost"
Camera="CanonS95"
function USAGE()
{
cat << EOF
Jarv's Automagic Photo Renamer
SUPER ALPHA VERSION; NOT EVERYTHING IMPLEMENTED; YOU HAVE TO COPY AND PASTE THE MV COMMANDS CURRENTLY :^)
USAGE: ./jarv_photo_renamer.sh JPEGS
OPTIONS:
-p Photographer (Default: ${Photographer})
-c Camera (Default: ${Camera})
EOF
}
while getopts ":p:c:?" Option
do
case $Option in
p ) Photographer=$OPTARG;;
c ) Camera=$OPTARG;;
n ) DRYRUN=$OPTARG;;
? ) USAGE
exit 0;;
* ) echo ""
echo "Unimplemented option chosen."
USAGE # DEFAULT
esac
done
#OK, now we should have our options
cat <<EOF
Well, here's what I understood / defaulted to:
Photographer = ${Photographer}
Camera = ${Camera}
EOF
if [ ${CaveName}=="" ]
then
echo "No CaveName set. Please enter a CaveName: "
read CaveName
fi
shift $(($OPTIND - 1))
# Decrements the argument pointer so it points to next argument.
# $1 now references the first non option item supplied on the command line
#+ if one exists.
PWD=` pwd `
for JPEG in $*
do
# Use exiftool to read Create Date directly form within JPEG
# Awk selects fourth non-whitespace bit (the actual date)
# Nb: Could use exiftool itself to rename files + act on a stream, probably faster
DateTime=` exiftool -d "%Y-%m-%d_%Hh%Mm" -createdate "${JPEG}" | awk '{print $4}'`
new="${DateTime}-${Photographer}-${Camera}-${CaveName}-${JPEG}"
echo mv "${JPEG}" "${new}"
done