DEV Community 👩‍💻👨‍💻

Cover image for QR code reader for OS X
Sergey Fedotov
Sergey Fedotov

Posted on

QR code reader for OS X

Hello, there! I want to share with you how you can extend the functionality of your Mac OS X. To do this, you will need the Homebrew package manager to install a couple of small utilities.

With it you can set “zbar” to decode a QR code and “pngpaste” to get a screenshot from the clipboard to paste into a file.

Run this in the Terminal to install the utilities from Homebrew:

brew install zbar pngpaste
Enter fullscreen mode Exit fullscreen mode

And for convenience you can encapsulate it in a separate script:

#! /bin/bash

FILENAME="$TMPDIR$RANDOM.png"   # Generates a file name
pngpaste "$FILENAME"            # Paste screenshot into file
zbarimg -q --raw "$FILENAME"    # Will try to decode QR-code
rm -rf "$FILENAME"              # Removing file for security
Enter fullscreen mode Exit fullscreen mode

Remember to make the script executable using command: chmod + x

Highlight the QR code on screen using “Shift + Control + Command + 4” and just run the script!

I also shared the script on my Dropbox

Note: for correct results, scan non-stylized QR codes

Top comments (1)

asahiocean profile image
Sergey Fedotov Author

By the way, you can also use an alias for the terminal:

alias qrpaste='zbarimg -q --raw <(pngpaste -)'
Enter fullscreen mode Exit fullscreen mode

Update Your DEV Experience Level:


Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. 🛠