Skip to content

Instantly share code, notes, and snippets.

@shello
Created July 5, 2017 15:27
Show Gist options
  • Save shello/3d3ba62ab1e02ee8cfad0e14ad54444b to your computer and use it in GitHub Desktop.
Save shello/3d3ba62ab1e02ee8cfad0e14ad54444b to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Interactively capture a screenshot (using the cursor), and decode any 1D or 2D
# barcodes in the image (such as QR Code, EAN-13, etc...)
#
# OS X / macOS only
# Requires:
# - zbar (http://zbar.sourceforge.net/, `brew install zbar`)
# - screencapture (included with the system)
function screenqr() {
for cmd in zbarimg screencapture; do
type "$cmd" >/dev/null 2&>1 || {
echo "$0: '$cmd' is required but could not be found. Exiting." >&2
return 1
}
done
tmpfile=$(mktemp)
screencapture -i "$tmpfile" && zbarimg --quiet "$tmpfile"
rm "$tmpfile"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment