ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: swsearcy on October 08, 2013, 11:37:19 PM

Title: Updating XMP Subject field
Post by: swsearcy on October 08, 2013, 11:37:19 PM
Lightroom uses the pipe (|) symbol as the separator for hierarchical keywords.  I would like to use a slash (/) instead.  I updated the .ExifTool_config file by adding the following as the last composite tag:

        # Microsoft Style Hierarchical Subject
        MSHS => {
            Require => 'HierarchicalSubject',
            ValueConv => '$val =~ s/\|/\//g; $val',
        },

I have an image (test.jpg) and issue the following commands with results included.


C:\Temp>exiftool -Subject test.jpg
Subject                         : Events|Activities|Soccer

C:\Temp>exiftool -HierarchicalSubject test.jpg
Hierarchical Subject            : Events|Activities|Soccer

C:\Temp>exiftool -MSHS test.jpg
MSHS                            : Events/Activities/Soccer

C:\Temp>exiftool "-Subject<MSHS" test.jpg
    1 image files updated

C:\Temp>exiftool -Subject test.jpg
Subject                         : Events|Activities|Soccer

C:\Temp>exiftool -HierarchicalSubject test.jpg
Hierarchical Subject            : Events|Activities|Soccer

C:\Temp>exiftool -MSHS test.jpg
MSHS                            : Events/Activities/Soccer


I am struggling to understand how MSHS can return the correct value but why the assignment of that value fails.  I know it's something simple, but for the life of me I can't figure it out.

I can clearly update the Subject tag given the following commands/results:


C:\Temp>exiftool "-Subject=Events/Activities/Soccer" test.jpg
    1 image files updated

C:\Temp>exiftool "-Subject" test.jpg
Subject                         : Events/Activities/Soccer


Any insight would be appreciated very much.

Thanks!
Title: Re: Updating XMP Subject field
Post by: Phil Harvey on October 09, 2013, 07:58:19 AM
The complication comes from the fact that HierarchicalSubject is a list-type tag, so you need to loop through all of the items in the list, something like this:

        MSHS => {
            Require => 'HierarchicalSubject',
            ValueConv => q{
                my @list = ref $val eq 'ARRAY' ? @$val : $val;
                s/\|/\//g foreach @list;
                return \@list;
            },
        },


- Phil
Title: Re: Updating XMP Subject field
Post by: swsearcy on October 09, 2013, 12:56:09 PM
Thanks so much Phil!  That worked perfectly.
Scott