ExifTool Forum

ExifTool => Newbies => Topic started by: afx on February 14, 2014, 05:40:49 PM

Title: How to enclose keywords in quotes?
Post by: afx on February 14, 2014, 05:40:49 PM
Hi,
I am exporting images from Lightroom.
Lightroom uses "," to separate keywords so keywords that contain spaces are easy.
But then I want to send them to a system that thinks the space is also a keyword separator and uses quotes for keywords with spaces.
So
Bon Ami,dog,rhodesian ridgeback
will result in 5 keywords:
Bon Ami dog rhodesian ridgeback
So I want to convert my keywords to
"Bon Ami",dog,"rhodesian ridgeback"
before sending them off.

Is there an easy way to do this with exiftool or do I have to parse the whole stuff myself, mangle it and write it back?

thx
afx
Title: Re: How to enclose keywords in quotes?
Post by: Phil Harvey on February 15, 2014, 07:13:30 AM
I'm not sure if it helps, but you can quote all keywords in the exiftool output like this:

exiftool -sep '","' -p '"$keywords"' some.jpg

(the above quoting is for Mac/Linux, but doing this in Windows could be tricky)

There are other alternatives, including creating a user-defined Composite tag to do whatever parsing you want.

- Phil
Title: Re: How to enclose keywords in quotes?
Post by: StarGeek on February 15, 2014, 04:52:08 PM
Here's a config file I worked up.  Hopefully this will do what you want.  It will check the keywords in a file and put quotes around them if there is a space in the keyword. 

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
QuotedKeywords => {
          Require => 'Keywords',
          ValueConv => q{
            my @list = ref $val ? @$val : ($val);
            my $changed;
            m/ / and $_ = qq#"$_"# and $changed = 1 foreach @list;
            return $changed ? \@list : undef;
          },
        },
    },
);

1;  #end


So, you could use this command:
ExifTool -config Path/to/config/file -if "$QuotedKeywords" "-keywords<QuotedKeywords" <DIR/FILE>

Now for the possible problem.  First, I just checked Lightroom 4 (windows) and it uses the xmp:Subject tag, and the iptc:keyword tag.  So, unless you know which tag the system you're sending them to uses, you might want to use this line, though you could add in a QuotedSubject tag to the config file as well if you desired

ExifTool -config Path/to/config/file -if "$QuotedKeywords" "-keywords<QuotedKeywords" "-subject<QuotedKeywords" <DIR/FILE>

edit:

Here's example output from the file I tested and saved the meta from Lightroom 4
exiftool  -keywords -subject -quotedkeywords Test.jpg
Keywords                        : Bon Ami, dog, rhodesian ridgeback
Subject                         : Bon Ami, dog, rhodesian ridgeback
Quoted Keywords                 : "Bon Ami", dog, "rhodesian ridgeback"