Keeping end spaces from DLGSTRING

Trying to use ExifTool in conjunction with DO to write working custom commands to prepend or append a custom string to an existing metadata field, such as Comment. My code looks something like this:

@set descprfx={dlgstring|Enter string to prepend to Comment:}
ExifTool -m "-EXIF:XPComment<{$descprfx}$EXIF:XPComment" .

In many cases, I’m going to want to use this particular command with a string that ends in a space, such as “Prefix to comment; ”, but in my tests so far, the trailing space is being stripped, which I suspect is being done by DOpus. If so, is there some way to have it preserved, or can something be implemented to enable preserving it? Otherwise, I guess I’ll have to make two versions of the command, and choose which one to use depending on whether I want a space or not.

I think it's the @set line removing spaces rather than the {dlgstring|...}. Try this:

ExifTool -m "-EXIF:XPComment<{dlgstring|Enter string to prepend to Comment:}$EXIF:XPComment" .

(Although I would expect you need a filepath or something else in that command line for it to work? Or does ExifTool automatically apply itself to some/all files if no path is specified?)

Unfortunately, putting {dlgstring} directly in the ExifTool command line is even less optimal than creating two versions (space or no space) of the custom command, since I’m actually using it to append multiple fields in one fell swoop, as in:

@set descprfx={dlgstring|Enter string to prepend to Description/Subject/Title/Comment}
ExifTool -m "-EXIF:ImageDescription<{$descprfx}$EXIF:ImageDescription" "-EXIF:XPSubject<{$descprfx}$EXIF:XPSubject" "-IPTC:ObjectName<{$descprfx}$IPTC:ObjectName" "-XMP:Title<{$descprfx}$XMP:Title" "-EXIF:XPComment<{$descprfx}$EXIF:XPComment" "-XMP:UserComment<{$descprfx}$XMP:UserComment" .

I’d have to run ExifTool separately for each one, which would be excruciatingly slow.

The single dot . at the end tells ExifTool to operate on all applicable files in the current directory.

It looks like you have a $ after every {$descprfx}, so you could move that character to the end of the @set line to solve things.

@set will remove leading and trailing spaces, but it won't modify spaces inside the string.

@set descprfx={dlgstring|Enter string to prepend to Description/Subject/Title/Comment}$
ExifTool -m "-EXIF:ImageDescription<{$descprfx}EXIF:ImageDescription" "-EXIF:XPSubject<{$descprfx}EXIF:XPSubject" "-IPTC:ObjectName<{$descprfx}IPTC:ObjectName" "-XMP:Title<{$descprfx}XMP:Title" "-EXIF:XPComment<{$descprfx}EXIF:XPComment" "-XMP:UserComment<{$descprfx}XMP:UserComment" .

(For a cleaner approach, you could use scripting, but I don't think you need that here... Although you may find you run into Windows command-line length limits if you type a large comment.)

Hey, that works! Thanks!

1 Like