Here's my script that consistently messes things up:
#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
pic=0
function jumpingjack () {
echo -e "What annotations file will I be using?"
read -e thelist
#Allowing for, and correcting, the trailing space in interactive mode
if [[ "$thelist" ]]; then
capfile1=${thelist% *}
else
capfile1=$thelist
fi
}
jumpingjack
while read file1
do
fixid=$(exiftool -s -S -IPTC:FixtureIdentifier "$file1")
if [ -n "$fixid" ]; then
echo "Event data present in $file1"
exiftool -fast5 -overwrite_original_in_place -q -P -ObjectName= -Title= "$file1"
echo "Writing data to Title fields"
exiftool -fast5 -overwrite_original_in_place -q -P -ObjectName="$fixid" -XMP:Title="$fixid" "$file1"
fi
objnm=$(exiftool -s -S -IPTC:ObjectName "$file1")
if [ -n "$objnm" ]; then
echo "Title data present in $file1."
exiftool -fast5 -overwrite_original_in_place -q -P -FixtureIdentifier= -Event= "$file1"
echo "Writing data to Event fields"
exiftool -fast5 -overwrite_original_in_place -q -P -FixtureIdentifier="$objnm" -XMP:Event="$objnm" "$file1"
fi
#pic=$[pic+1]
((pic++))
done<"$capfile1"
echo -e "\t\tA total of $pic items annotated.\n"
IFS=$SAVEIFS
What I mean is, when I run it, it sets the Title tag over the Event tag, instead of switching them. Years ago, I had written a script (since lost) that did this using exiv2. Am I putting things in the wrong order? Should the script read in the data from both tags and then swap them. If so, could someone suggest a way this could be done?
Carver
Why use a script? Just switch them.
exiftool -title= -event= -tagsfromfile @ "-Title<Event" "-Event<Title" FileOrDir
Example:
C:\>exiftool -Title -Event X:\!temp\Test3.jpg
Title : 001_001
Event : xmp:Event
C:\>exiftool -P -overwrite_original -title= -event= -tagsfromfile @ "-Title<Event" "-Event<Title" X:\!temp\Test3.jpg
1 image files updated
C:\>exiftool -Title -Event X:\!temp\Test3.jpg
Title : xmp:Event
Event : 001_001
Edit: Just realized your case checked for the possibility of one tag or the other being empty. Added correction to above command to take that into account. New example for such a case:
C:\>exiftool -Title -Event X:\!temp\Test3.jpg
Title : 001_001
C:\>exiftool -P -overwrite_original -title= -event= -tagsfromfile @ "-Title<Event" "-Event<Title" X:\!temp\Test3.jpg
1 image files updated
C:\>exiftool -Title -Event X:\!temp\Test3.jpg
Event : 001_001
Quote from: StarGeek on May 15, 2017, 11:32:59 PM
Why use a script? Just switch them.
Because by way of a script, I can make the changes to more than one file, by name instead of wildcards and guessing with partial names. I don't think I would use such a command on a whole directory. Sometimes I just notice tags that would make better sense "swapped."
I'm wondering right now if this part of your one-liner,
exiftool -title= -event= -tagsfromfile @ "-Title<Event" "-Event<Title" FileOrDirwould work as a command IN a script. It would certainly simplify matters. I think I'll try it.
Carver
You can specify as many file names as you want on a command line.
- Phil