Alphabetize list-type tags

Started by wywh, January 11, 2024, 04:07:22 AM

Previous topic - Next topic

wywh

Quote from: Phil Harvey on January 12, 2024, 01:22:15 PMhow you got the empty element without trying unless natcomp generated it

I believe natcomp generated it when I was trying to clear old Subject list with minimum effort with Subject=''.

After deleting natcomp block from the command it works as expected and Subject line is nuked:

exiftool -a -G1 -s -sep '//' -XMP:All image.jpg                                    
[XMP-dc]        Subject                         : a

exiftool -tagsFromFile @ -XMP-dc:Subject -XMP-dc:Subject='' -api NoDups=1 -execute '-Subject<${Subject;$_=join ";", sort{natcomp} split ";"}' -common_args -m -P -overwrite_original -sep ';' image.jpg
    1 image files updated
    1 image files updated

exiftool -a -G1 -s -sep '//' -XMP:All image.jpg
[XMP-dc]        Subject                         :

exiftool -tagsFromFile @ -XMP-dc:Subject -XMP-dc:Subject='' -api NoDups=1 -m -P -overwrite_original -sep ';' image.jpg
    1 image files updated

exiftool -a -G1 -s -sep '//' -XMP:All image.jpg
[null]

-Matti


StarGeek

Quote from: Phil Harvey on January 12, 2024, 01:22:15 PM-XMP-dc:Subject=''

on the command line is equivalent to:

-XMP-dc:Subject=

because the quotes are stripped by the command shell.

I don't know what I did but I did a quick test before and ended up with a 0 length tag.  Of course, now I can't reproduce it, so I did something wrong.

QuoteBut I don't know how you got the empty element without trying unless natcomp generated it.

I hope not.  I tested a file using wywh's command and it didn't happen for me.  Back to testing it is.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

StarGeek

Ah, there it is.  You have the -m (-ignoreMinorErrors) option option in the command.  You are clearing Subject before the -TagsFromFile, but then copying the empty Subject back into itself. From the docs
QuoteNote that this causes missing values in -tagsFromFile, -p and -if strings to be set to an empty string rather than an undefined value.

Example:
C:\>exiftool -G1 -a -s -subject y:\!temp\Test4.jpg

C:\>exiftool -G1 -a -s -m "-Subject<$Subject" y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -G1 -a -s -subject y:\!temp\Test4.jpg
[XMP-dc]        Subject                         :
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

...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 ($).

wywh

Quote from: StarGeek on January 12, 2024, 05:28:36 PMAh, there it is.  You have the -m (-ignoreMinorErrors) option option in the command

Thanks again. I have used -m because AFAIR in some distant past some command failed without it, and also as a means to prevent benign warnings from littering the output. So I deleted it form the command below. To clear old Keywords, use just Subject='', and then start to fill the Keyword list again. No more empty Subject string left behind.

exiftool -XMP-dc:Title='Title' -XMP-photoshop:CaptionWriter='Author' -XMP-dc:Description='Description' -XMP-xmp:Rating=3 -tagsFromFile @ -XMP-dc:Subject -XMP-dc:Subject='Keyword 1;Keyword 2' -api NoDups=1 -execute '-Subject<${Subject;$_=join ";", sort{natcomp} split ";"}' -common_args -P -overwrite_original_in_place -sep ';' image.jpg
- Matti

wywh

It seems it is best to avoid commas inside image IPTC:Keywords and XMP-dc:Subject (and also in movie Keys:Keywords) because macOS 14.2.1 Sonoma Photos.app forces comma as a Keyword separator anyway. If there is a comma inside a IPTC/XMP Keyword, then Photos.app splits the Keyword and the pieces are grayed out in its info dialog.

On the other hand, Photos.app accepts semicolon inside those image and movie Keywords.

I heard that Adobe XMP SDK treats semicolon and comma by default the same in Keywords.

- Matti