automate saving screenshot (already in clipboard) to a file in bash
screencapture is a CLI tool built into macOS for taking screenshots, in /usr/sbin/screencapture.

To take a screenshot and save it to screenshot.png:



screencapture -x screenshot.png


To screenshot a region, you can use -R, where x,y are the coordinates of the top-left and w,h is width and height of the capture.

screencapture -x -Rx,y,w,h /path/to/capture.png


To interactively choose a region, use -i

screencapture -i screenshot.png