MacOS: saving images from the clipboard using `pngpaste` is faded and white

copy/pastemacosterminal

When I take a screenshot on macOS, and use pngpaste a1.png to save it, the image is faded:
enter image description here

This only happens when I take a fullscreen screenshot using CMD+SHIFT+3, and not with CMD+SHIFT+4.

Best Answer

Using these instead works fine:

function pngpaste() {
    local name="${1}"
    ensure-args name @MRET
    ensure isDarwin @MRET

    [[ "$name" =~ '\.png$' ]] || name+=.png

    osascript -e "tell application \"System Events\" to ¬
                  write (the clipboard as «class PNGf») to ¬
                          (make new file at folder \"$(pwd)\" with properties ¬
                                  {name:\"${name}\"})"
}
function jpgpaste() {
    local name="${1}"
    ensure-args name @MRET
    ensure isDarwin @MRET


    [[ "$name" =~ '\.jpg$' ]] || name+=.jpg

    osascript -e "tell application \"System Events\" to ¬
                  write (the clipboard as JPEG picture) to ¬
                          (make new file at folder \"$(pwd)\" with properties ¬
                                  {name:\"${name}\"})"
}

Usage:

pngpaste a1.png