Dereference New Tag Value for assignment

Started by busywait, December 15, 2017, 10:31:35 AM

Previous topic - Next topic

busywait

Hello,

I can see how to assign one tag to the value of another. For example, this assigns the old value of Title to Comment, and assigns the string "New Title" to Title:
exiftool -Title="New Title" "-Comment<${Title}" a.jpg

Is there a way to reference the new value for Title ("New Title" in this case) in the assignment to Comment, so that the same string is written to Title and Comment?

Phil Harvey

Typically it is done like this:

exiftool -title="New Title" -comment="New Title" a.jpg

If you want the value of a single variable to be applied to both, typically this is done via a script or batch file, but you could do this with the -userparam option if you really wanted:

exiftool -userparam myvar="New Title" "-title<$myvar" "-comment<$myvar" a.jpg

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

busywait

Aha -  userparams looks like helpful magic for me, thanks.

Phil Harvey

I should mention that the UserParam option is slower than the scripting solution because copying tags like this adds the unnecessary step of reading tags from the 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 ($).

busywait

Is is possible to dereference environment variables, like $ENV{title_value}?

-Comment<$ENV{title_value} doesn't work.

Phil Harvey

That would be done via the normal shell features.  For Mac:

exiftool "-comment=$COMMENT" a.jpg

where COMMENT is an environment variable.

Note that you use "=" here because as far as ExifTool is concerned you are writing a constant string.  The "$COMMENT" is expanded by the shell.

The exact syntax depends on the shell you are using.

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

busywait

Thanks - at the moment my exiftool options are mostly in an args file which I run like .\exiftool -@ mytags.txt $*, so I don't get shell expansions.

One reason I try to keep everything in config files is to avoid confusing myself with quotes and escaping % signs :)

I'll break out the ones I need to the command line.