Is it possible to read QR code on macOS using webcam?

Solution 1:

Yes, zbarcam is not available on MacOS, but instead you can use imagesnap and then combine it with zbarimg (from zbar package).

The simplest possible solution would be:

imagesnap -w 1 snap.jpg
zbarimg -1 --raw -q -Sbinary snap.jpg

You can automate it to wait for first successful reading:

function scan_qr() {
  local result=""
  while true; do
    imagesnap -q -w 1 /tmp/snap.jpg
    result="$(zbarimg -1 --raw -q -Sbinary /tmp/snap.jpg)"
    [[ -n $result ]] && break
    sleep 1
  done
  echo "${result}"
}
scan_qr

Ready to go script, using the same mechanism, you can find HERE.

At the top of the file you can find usage info:

#
# EXAMPLES:
#
#  Just print the QR code
#
#    ./scan-qrcode.sh
#
#  Copy QR code to clipboard
#
#    ./scan-qrcode.sh | pbcopy
#
#  Import paper secret key from QR code:
#
#    ./scan-qrcode.sh | paperkey --pubring public-key.asc | gpg --import
#

I hope that helps.