How to enclose keywords in quotes?

Started by afx, February 14, 2014, 05:40:49 PM

Previous topic - Next topic

afx

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

Phil Harvey

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

StarGeek

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"
* 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).