ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: philbond87 on September 17, 2021, 07:10:47 PM

Title: Updating [XMP] Prefs tag
Post by: philbond87 on September 17, 2021, 07:10:47 PM
The -xmp:prefs tag contains a string that is made up of multiple values (eg. Tagged:0, ColorClass:0, Rating:5, FrameNum:-00001)

I'm currently updating the -rating, -label and -colorclass tags of various files and I noticed that in some cases Photo Mechanic won't accurately display the updated ratings if they aren't in agreement with what's in that -xmp:prefs tag.

Currently my application uses this line to write the -rating, -label and -colorclass tags:
-overwrite_original_in_place -rating=5 -label=Yellow -colorclass=2

How would I include a line that will, if the -xmp:prefs tag exists in a file, update it to match the tags that I'm editing in the line above? (basically conditionally changing the ColorClass and Rating parts of the prefs tag?

Thanks,
Phil
Title: Re: Updating [XMP] Prefs tag
Post by: StarGeek on September 18, 2021, 12:00:27 AM
You could do it either directly as part of your command.  In this case if Prefs did not already exist you would get Warning: [minor] Tag 'Prefs' not defined which you could ignore.
-overwrite_original_in_place -rating=5 -label=Yellow -colorclass=2 '-XMP:Prefs<${XMP:Prefs;s/Rating:\d+/Rating:5/;s/ColorClass:\d+/ColorClass:2/}'

Or you could run it as a separate command after your first command which would replace ColorClass/Rating with the appropriate tags.
-overwrite_original_in_place -if '$XMP:Prefs' '-XMP:Prefs<${XMP:Prefs;s/ColorClass:.*//}ColorClass:${ColorClass}, Rating:${Rating}, ${XMP:Prefs;s/.*Rating:\d+, //}'

I'm assuming this is for a Mac, as the use of -overwrite_original_in_place is rarely needed otherwise.  If it is for Windows CMD, change the single quotes to double quotes.
Title: Re: Updating [XMP] Prefs tag
Post by: philbond87 on September 18, 2021, 12:29:17 PM
Excellent, thank you (once again) @StarGeek.