I'm close to getting exiftool to rename files with a certain pattern but I can't quite make the last step work, getting rid of the space when '-T -FocalLength' is used. I'm close:
exiftool -a -d %Y%m%d-%H%M%S '-FileName<${CreateDate}_${FocalLength}_f${Aperture}_ISO${ISO}.jpg' DSC-0001.JPG
turns "DSC-0001.JPG" into "20180425-014512_24.0 mm_f4.0_ISO100.jpg" but I'm working toward "20180425-014512_24.0mm_f4.0_ISO100.jpg".
My script so far, named "exif1":
#!/bin/bash
VAR1=`/opt/local/bin/exiftool-5.26 -T -FocalLength $1`
VAR2="${VAR1//[[:space:]]/}"
/opt/local/bin/exiftool -a -d %Y%m%d-%H%M%S '-FileName<${CreateDate}_${VAR2}_f${Aperture}_ISO${ISO}.jpg' $1
Errors when it's run:
$ ./exif1 DSC-0001.JPG
Warning: [minor] Tag 'VAR2' not defined - DSC-0001.JPG
Warning: No writable tags set from DSC-0001.JPG
0 image files updated
1 image files unchanged
I see the problem, VAR2 in the last line isn't holding the value from the line before -- the way the command's set up it "should" be getting a value from exiftool. Except exiftool doesn't know anything about a "VAR2" and I can't figure out a way to pass the value into that command. I can't quite figure out how to get from here to completion and I'd really appreciate some assistance.
macOS 10.13.4
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)
exiftool 10.94 (using MacPorts package mangement tool)
David
Edit: Remove extraneous backtick, make sure pasted errors messages reflect this correction
You can also do the substitution directly in exiftool.
Try this for FocalLength
${FocalLength;s/ //g}
Seriously? Seriously! Thank you! Don't know how long it would have been before I ran across that in the documentation.
This tool is really impressive. I first came across mention of it several links deep in something else and I couldn't find it again. Just as well because it gave me the impression of "this little utility that can do a few things." Searched for it by name the other day and this time, I came in through the front door.
Thanks again!
David