News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

help needed with copying tags within file

Started by godspeedphoto, November 05, 2019, 10:54:13 AM

Previous topic - Next topic

godspeedphoto

Hi, i have seem to hit a wall on trying to script out an exiftool command, and could use the community's help.

I use ACDSee as my current DAM, and when hierarchical keywords are embedded into image files, they are written in pipe delimited format to the acdsee xmp block.  What i would like to do is copy these values, exactly as they are, to the LR:hierarchicalsubject block.  Most importantly, i am trying to do all this by using the Windows "sendto" command, which allows me to highlight multiple files within ACDSee (jpgs, tiff,  AND rw2 files) and then use "sendto" command to pass all the files into this process (evaluating one file at a time, i presume).

i tried to use this thread as a baseline: https://exiftool.org/forum/index.php?topic=7804.0

and here are a few lines that i have tried:
exiftool.exe -execute -srcfile %d%f.xmp -if "$fileextension eq rw2" -common_args "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k

exiftool.exe -execute -ext rw2 -srcfile %d%f.xmp -common_args "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k

i am using exiftool vs 11.62 at the moment, and it seems that when i pass a JPG file to either of these, the jpg xmp block is updated.  But when i pass in a RW2 file, it says no writeable tags are available, and the corresponding xmp file is not updated.

TLDR, i am looking for a way to:
- if embeddable file type (ie, jpg, tiff, etc) copy the acdsee keywords to the lr:hiearchicalsubject tag directly to the same file
- if raw file (ie, rw2), only look in the corresponding xmp file and copy the acdsee keywords to the lr:hiearchicalsubject

any help would be much appreciated!
-Joe

Phil Harvey

First, your command is equivalent to these 2 commands:

1. exiftool.exe "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k

2. exiftool.exe -srcfile %d%f.xmp -if "$fileextension eq rw2" "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k

...which I don't think is what you intended.  The first command will write RW2 files, and the second command will read from the RW2 file (-tagsFromFile @ is implied).  I think you want to do this in your second command:

exiftool.exe -srcfile %d%f.xmp -ext rw2 -tagsfromfile %d%f.xmp "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k

Here I have replaced your -if condition with the much more efficient -ext option.

So your combined command would be:

exiftool.exe -ext -rw2 -execute -ext rw2 -srcfile %d%f.xmp -tagsfromfile %d%f.xmp -common_args "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k

Here I have re-arranged to put "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" at the end because it was common to both commands.

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

godspeedphoto

#2
thanks for such a fast response Phil!

How can i get this command to also run for other types of files that do NOT require an xmp buddy file, such as jpgs or tiffs?  so that if i passed in a jpg file to this command, it would not attempt to create or look in an xmp file, but instead just write out the acdsee keywords to the lr hierarchical subject directly into the file?  all the while, using the SAME command, that if i passed in a raw file, it would only write the tags to the xmp buddy file?  is that possible with a single command?

UPDATE: i think i figured it out? i removed the first "-ext rw2" and it seems to work as i need.

which is very strange, because one of my earlier attempts was this:
exiftool.exe -execute -ext rw2 -srcfile %d%f.xmp -common_args "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k

which is very similar to your code line, except mine is missing the tagsfromfile...is that what i was missing?

Phil Harvey

It should already do that.  I have just excluded RW2 from the first command with -ext -rw2 -- the other file types should be processed.

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

godspeedphoto

i think i found the point of confusion...my original 2 lines of code are not run together, they are just 2 different versions of what i have tried.  I am looking for a single line command that can encapsulate the entire logic (write directly to jpg/tiff/etc, or, if raw files, write to the xmp file).

is that possible, or do i need multiple lines?

Phil Harvey

I didn't even look at your second command line.  I was commenting only on your first attempt.

Again, I think the combined command I provided will give you what you want.

I think the point of confusion may be that you don't understand how the -execute option works.

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

godspeedphoto

Phil, you are probably correct on my confusion of -execute...
from the documentation: Execute command for all arguments up to this point on the command line (plus any arguments specified by -common_args)

so with your line of code: exiftool.exe -ext -rw2 -execute -ext rw2 -srcfile %d%f.xmp -tagsfromfile %d%f.xmp -common_args "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k

are there 2 commands here?  the "ext -rw2" is command 1, and the "-ext rw2 -srcfile %d%f.xmp -tagsfromfile %d%f.xmp" is command 2?  I also assume that anything after the "-common_args" line is run regardless?

when i run your command against a jpg, i get this in the return window
No file with specified extension
No file with specified extension

when i run it against a rw2 file, i get this:
No file with specified extension
1 image files updated


If i remove the first "-ext rw2" command, it looks like it works for both jpgs and rw2, where the jpgs have the embedded changes, and the rw2 file's xmp file is updated...i am just trying to make sure i understand this correctly, since i will eventually be using this across thousands of files..
on closer inspection, did you mean to write "-ext -rw2"?  is that to ignore rw2 files?  shouldnt it be "--ext rw2" instead?

thanks again for all your help Phil

Phil Harvey

Quote from: godspeedphoto on November 05, 2019, 12:17:12 PM
so with your line of code: exiftool.exe -ext -rw2 -execute -ext rw2 -srcfile %d%f.xmp -tagsfromfile %d%f.xmp -common_args "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k

are there 2 commands here?

Yes.  The commands are:

1. exiftool -ext -rw2 "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k

2. exiftool -ext rw2 -srcfile %d%f.xmp -tagsfromfile %d%f.xmp "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k

Quotewhen i run your command against a jpg, i get this in the return window
No file with specified extension
No file with specified extension

My mistake.  It should be --ext rw2 instead of -ext -rw2 as the first option in the command.

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

godspeedphoto

i think i get it now!  :)

and to reaffirm that, i now need to add in additional logic that handles the case where a passed in file does NOT have acdsee keywords, BUT the LR-hierarchicalsubject value is populated.  In that case, i would like to blank out the lr_hierarchicalsubject, to keep those 2 tags in sync.

in that case, would i change the command to this?
exiftool.exe -XMP-lr:HierarchicalSubject= -execute --ext rw2 -execute -ext rw2 -srcfile %d%f.xmp -tagsfromfile %d%f.xmp -common_args "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k

which should execute these 3 commands:
1. exiftool -XMP-lr:HierarchicalSubject= "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k  (blanks out lr:hierarchicalsubject always)
2. exiftool --ext rw2 "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k   (copies acdsee keywords to lr_hierarchicalsubject...will generate warning if acdsee keywords is blank)
3. exiftool -ext rw2 -srcfile %d%f.xmp -tagsfromfile %d%f.xmp "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k   (for file with extension rw2, look in the xmp file to copy the acdsee keywords to the lr_hierarchicalsubject in the xmp file)

does that work, or is there a better way to handle the syncing of lr:hierarchicalsubject with acdsee-keywords?  I figured always wiping out lr:hierarchicalsubject first seems appropriate, unless i am misunderstanding the order of operations here?

-Joe

Phil Harvey

Hi Joe,

What you have done with the 3-part command should work, but it would be more efficient to do it in 2 parts:

exiftool.exe --ext rw2 -execute -ext rw2 -srcfile %d%f.xmp -tagsfromfile %d%f.xmp -common_args -XMP-lr:HierarchicalSubject= "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k

This command will also clear the XMP-lr:HierarchicalSubject tag unless XMP-acdsee:keywords exists to overwrite it.

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

godspeedphoto

#10
thanks Phil...

i tried your suggestion, which makes complete sense,btw, and it seems to work as expected for NON rw2 files (jpgs, tiffs), but not with rw2 files now.

so this command
exiftool.exe --ext rw2 -execute -ext rw2 -srcfile %d%f.xmp -tagsfromfile %d%f.xmp -common_args -XMP-lr:HierarchicalSubject= "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k
turns into the following commands depending on if rw2 or NOT rw2:

rw2 files: exiftool.exe -ext rw2 -srcfile %d%f.xmp -tagsfromfile %d%f.xmp -XMP-lr:HierarchicalSubject= "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k

non rw2 files: exiftool --ext rw2 -XMP-lr:HierarchicalSubject= "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -overwrite_original_in_place -k


for a given rw2 file here are the scenarios and results:
1. rw2's xmp file contains acdsee keywords AND lr:hierarchicalsubject:  the lr:hierarchicalsubject block is deleted, acdsee keywords are NOT added after the deletion.
2. rw2's xmp file contains acdsee keywords ONLY (no lr:hierarchicalsubject):  0 image files updated, 1 image files unchanged. no lr_hierarchicalsubject keywords added.

since the -tagsfromfile is not being used for non rw2 files (jpgs), perhaps the order of the -XMP-lr:HierarchicalSubject= "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" is causing an issue along with -tagsfromfile being included in that command?

we are sooo close!  I'm sure its down to some nuance that i can't figure out...

-Joe

Phil Harvey

I'll test this first thing tomorrow to see if I can reproduce this.

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

Phil Harvey

I think I figured out the problem.  It is an order of operations thing.  All of the tags are copied at the point in the command where the -tagsFromFile is found.  So unfortunately we need to break this apart a bit:

exiftool.exe --ext rw2 -XMP-lr:HierarchicalSubject= "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -execute -ext rw2 -srcfile %d%f.xmp -XMP-lr:HierarchicalSubject= -tagsfromfile %d%f.xmp "-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords" -common_args -overwrite_original_in_place -k

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

godspeedphoto

ah, thanks Phil, i figured it was something along those lines.

unfortunately, this new line is longer than the max 260 characters allowed in the Target of a Windows shortcut :(

is it possible to wrap the "meat" of these commands into its own file (i think its the -@ switch?), and call that file from the Windows shortcut?

Phil Harvey

Yes.

Use this file:


--ext
rw2
-XMP-lr:HierarchicalSubject=
-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords
-overwrite_original
-execute
-ext
rw2
-srcfile
%d%f.xmp
-XMP-lr:HierarchicalSubject=
-tagsfromfile
%d%f.xmp
-XMP-lr:HierarchicalSubject<XMP-acdsee:keywords
-overwrite_original
-k


and this command:

exiftool -@ YOUR_ARGS_FILE

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

godspeedphoto

again, thanks so much Phil.

so, the original command line works beautifully for both jpgs and rw2 files if i run it in a powershell window (see exiftool1.png).

using a slightly modified ARG file (changed overwrite_original to overwrite_original_in_place, and added -v3 switch) so that i can use the command via the Windows Sendto shortcut:
--ext
rw2
-XMP-lr:HierarchicalSubject=
-XMP-lr:HierarchicalSubject < XMP-acdsee:keywords
-overwrite_original_in_place
-execute
-ext
rw2
-srcfile
%d%f.xmp
-XMP-lr:HierarchicalSubject=
-tagsfromfile
%d%f.xmp
-XMP-lr:HierarchicalSubject < XMP-acdsee:keywords
-overwrite_original_in_place
-k
-v3


i am seeing strange behavior, depending on if its a jpg or rw2 file.  See attached exiftool2.png to see the results.  My understanding of how the windows sendto shortcut works, is that it automatically adds the filepath to the end of the command.  So to mimic that behavior, i am using powershell to call the various command scenarios.  If i put the path to the file before the call to -@ or after, different things happen depending on the file extension.
rw2 fles only work if the filename is AFTER the -@ argfile, while JPG files only work if the filename is BEFORE the -@ argfile.

I've tried various adjustments this morning, but i can't seem to figure out why the 2 types of extensions behave differently depending on where the filename is placed in the exiftool command.

i really do appreciate all the help Phil, you are certainly going above and beyond at this point...

-Joe

Phil Harvey

Right.  For the file to be applied to both commands, you would need to use -common_args.  Sorry, I didn't think of this before.

exiftool -@ YOUR_ARGS_FILE -common_args

Then the file names come after this.

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

godspeedphoto

that did it!  thank you so much for helping me through this.  I did learn alot about how exiftool processes commands in this exchange, so hopefully i can figure out any additional tweaks in the future :)

so the addition of -common_args tells exiftool that the "invisible" filepath (not shown but implied) should be sent to each of the commands within the ARGFILE, of which there are 2 commands, since there is ONE -execute causing the separation?

just wanting to make sure i understand the processing logic...

-Joe

Phil Harvey

Hi Joe,

Yes, the purpose of -common_args is to apply any arguments after this option to each -execute'd command on the command line (plus the last one, which doesn't need a -execute option).  The "invisible" filepath is added to the end of the command by Windows, so this works out nicely.

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

godspeedphoto

awesome Phil, thank you again so much for your assistance and for making this great tool available to the masses.

-Joe