Author Topic: How to enclose keywords in quotes?  (Read 1993 times)

afx

  • Newbie
  • *
  • Posts: 5
    • AFXImages
How to enclose keywords in quotes?
« 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

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16724
    • ExifTool Home Page
Re: How to enclose keywords in quotes?
« Reply #1 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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3803
Re: How to enclose keywords in quotes?
« Reply #2 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. 

Code: [Select]
%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"
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.