I found another problem:
By default, the screencapture
command outputs in jpg
format, and so when you give it a filename with .png
it fails to save to the file.
This is in spite of the documentation:
-t<format>
image format to create, default is png (other options include pdf, jpg, tiff and other formats)
So, when I changed the file extension to .jpg
it worked.
screencapture -i "/Users/YourUserName/Downloads/$KMVAR_DateTimeForFile screenshot.jpg"
It took a lot of testing and trial-and-error to discover this.
Based on your original macro and what I learned, I created and just posted this macro:
MACRO: ScreenCapture: Select Region & Save to File with Date/Time Stamp [Example]
It worked for using .jpg, .png, and .pdf
formats.
Please let us know if it works for you.