ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: busywait on December 15, 2017, 10:31:35 AM

Title: Dereference New Tag Value for assignment
Post by: busywait on December 15, 2017, 10:31:35 AM
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?
Title: Re: Dereference New Tag Value for assignment
Post by: Phil Harvey on December 15, 2017, 10:51:32 AM
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
Title: Re: Dereference New Tag Value for assignment
Post by: busywait on December 15, 2017, 11:05:22 AM
Aha -  userparams looks like helpful magic for me, thanks.
Title: Re: Dereference New Tag Value for assignment
Post by: Phil Harvey on December 15, 2017, 11:08:06 AM
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
Title: Re: Dereference New Tag Value for assignment
Post by: busywait on December 15, 2017, 11:18:35 AM
Is is possible to dereference environment variables, like $ENV{title_value}?

-Comment<$ENV{title_value} doesn't work.
Title: Re: Dereference New Tag Value for assignment
Post by: Phil Harvey on December 15, 2017, 11:24:00 AM
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
Title: Re: Dereference New Tag Value for assignment
Post by: busywait on December 15, 2017, 11:53:24 AM
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.