Switch Event tag and Title tag using bash script

Started by L_Carver, May 15, 2017, 10:05:41 PM

Previous topic - Next topic

L_Carver

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
____________
Screen name comes from a story my ex-wife and I worked on for several years and never got past the first chapter. Llewellyn Carver was a Welsh drow elf living somewhere in New York state. Message me if you're curious to find out more.

StarGeek

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
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

L_Carver

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" FileOrDir
would work as a command IN a script. It would certainly simplify matters. I think I'll try it.

Carver
____________
Screen name comes from a story my ex-wife and I worked on for several years and never got past the first chapter. Llewellyn Carver was a Welsh drow elf living somewhere in New York state. Message me if you're curious to find out more.

Phil Harvey

You can specify as many file names as you want on a command line.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).