Write arbitrary text followed by sequence number to title field

Started by garryknight, October 06, 2022, 02:13:26 PM

Previous topic - Next topic

garryknight

Short version
I have a number of jpeg files and want to write a title field to each of them. I want this title field to consist of some arbitrary text which is the same for each file, followed by a sequence number of an arbitrary number of input digits starting with a given input number. For example, I might want the title field of the first file to be "Saturday protest event - 0011", the next to be "Saturday protest event - 0012" and so on for all of the input files. The next time I process files, I might want the title field to be "Scrapbook 0301", "Scrapbook 0302", and so on.

Long version
I often photograph events, and I like to give my JPEGs filenames with sequential numbers, and also to have the title field contain arbitrary text followed by a sequence number. For example, filenames like 22-10-08-protest-0011 with titles like "Saturday protest event - 0011" and so on. If I want the title text to be the same as the filename, I know that I can use this command:

exiftool *.jpg "-Title<BaseName"

However, I often don't want the title text to be the same as the filename. I could do what I want using the laborious method of naming all of the files with the text that I want in the title, then using the above command to write the title fields, then renaming the files again, but there must be a quicker way that avoids problems with allowed filename characters.

I've searched this subforum using various search terms, e.g. "sequence number" and the nearest I've found to what I want is in this thread:

https://exiftool.org/forum/index.php?topic=9419.msg48723#msg48723

I think it's possible that this solution can be made to do what I want and, in particular, with some magic involving the FileSequence tag. While I found FileSequence in the description of Extra Tags I haven't been able to find anything telling me how to wrangle arbitrary number sequences from it.

Could somebody please show me an exiftool command that achieves what I want? If I haven't explained this clearly, please let me know and I'll try and explain it more simply. If it makes a difference, I'm using MacOS 12.6.


I used to program in Perl and also write complex shell scripts, but that was a few decades ago, and both look like "write-only language" to me nowadays, so please treat me like an intelligent but forgetful newcomer. Thanks.

StarGeek

That link has the correct command.  Since you don't want to change the filename, you just need to remove that part.  This assumes you want it padded with leading zeros to 4 digits.  Change the 4 in (4-length) to have a different width.  FileSequence normally starts at 0.  This command adds 1 to that so it counts up from one.  If you want to start at a different number, change the +1 to that starting number, i.e. +10 will start counting at 10.

Oops, just noticed a mistake in the linked command.  The padding will be wrong when the number gets higher.  Corrected command.  The +1 and 4 are still the numbers to change to adjust the command.

exiftool "-Title<My title ${FileSequence;$_=$_+1;$_=0 x(4-length).$_}" /path/to/files/

If this command is run under Unix/Mac/Powershell, swap double/single quotes to avoid variable interpretation.

Example with padding changed to three and start number 10
C:\>exiftool -P -overwrite_original "-Title<My title ${FileSequence;$_=$_+10;$_=0 x(3-length).$_}" y:\!temp\Test3.jpg y:\!temp\Test4.jpg
    2 image files updated

C:\>exiftool -G1 -a -s -title y:\!temp\Test3.jpg y:\!temp\Test4.jpg
======== y:/!temp/Test3.jpg
[XMP-dc]        Title                           : My title 010
======== y:/!temp/Test4.jpg
[XMP-dc]        Title                           : My title 011
    2 image files read
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

garryknight

That's great, thank you.

Is there some way of setting the number padding (4 or 3 in your example) within the command line? Or would I have to pass that in from a shell script?

StarGeek

I don't understand.  Everything shown above is on the command line.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

garryknight

Sorry. I was tired when I wrote that and wasn't thinking straight. Since there's no way I can memorise that command, I plan on putting it in a shell script file. Obviously I can use shell variables to replace the start number and number padding, and then pass those in when I run the script.

You've saved me a lot of hard work in my media asset management program, clicking on a photo, typing the title by hand including the number, clicking on the next photo, and so on, for perhaps dozens of photos. So thanks again for your help. I really appreciate it.

StarGeek

I can't help with the script part of it except to say that you'll need change the double quotes " into single quotes ' on a Mac.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype