Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import sys
import subprocess
import tempfile
import urllib
text =
chart_url_template = (''
chart_url = chart_url_template.format(data=urllib.quote(text))
with tempfile.NamedTemporaryFile(mode='w', suffix='.png') as f:
subprocess.check_call(['curl', '-L', chart_url],
stdout=f, stderr=sys.stderr)
subprocess.check_call(['qlmanage', '-p',])

This comment has been minimized.

Copy link

@Mic92 Mic92 commented Mar 17, 2013

Heres Is my version.

#!/usr/bin/env python2
import sys, os
import subprocess
import qrencode
from tempfile import mkstemp
from PIL import Image

def open_default(path):
    if sys.platform.startswith('darwin'):'open', path))
    elif == 'nt':
    elif == 'posix':'xdg-open', path))

args = sys.argv[1:]
if args:
  text = "".join(args)
  text =
_, _, image = qrencode.encode_scaled(text, 500)
_, path = mkstemp(".png"), "PNG")

It doesn't depend on the google api, but on qrencode.

$ pip install qrencode

So no internet connection is needed.
Instead of launching quicklook, it opens (hopefully) the default viewer of the underlying os.


$ echo "test" | qrcodify


$ qrcodify "test"

On linux it can be used like this, to encode the clipboard as qrcode:

$ xclip -o | qrcodify

On MacOS:

$ pbpaste | qrcodify

This comment has been minimized.

Copy link

@DaveCollinsJr DaveCollinsJr commented Mar 18, 2013

@zacharyvoase most impressive!


This comment has been minimized.

Copy link

@stou stou commented Mar 15, 2014

Nice idea.

Could not get the qrencode module to install in OS X mavericks

FWIW, I've put together this little script instead

# Author: Rasmus Stougaard

# requrements:
#  install qrencode
#   brew install qrencode

qrencode -o $tmpQrFile && qlmanage -p $tmpQrFile && rm $tmpQrFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment