2019-02-24 Transferring strings to a phone via QR codes

Sometimes I need to transfer some text (a link, a short note or something else) from my computer to my phone. A usual way is to send it via some cloud-based service – but I don’t really like it, since there is no such thing as cloud – only other people’s computers. While I am not rigorously opposed to such an idea, I do not like putting my personal stuff on somebody else’s machine without any good reason.

Another way is to email the thing – but I do not have an email client configured on my phone, and I really want it to stay that way. (I consider email to be a crucial part of my privacy/security. Having it on my phone puts me at significant risk – phones like to be stolen or lost, for instance.)

A few days ago, an idea of using QR codes came to my mind. I could encode my short text into such a code, display it on the monitor and then scan it using my phone’s camera.

Now, generating a QR code is a solved problem, so I didn’t expect any difficulties. I didn’t expect the task to be that easy, either. It turned out that instead of writing a dozen of pages of Pascal I could just put together a simple pipeline:

#!/bin/sh
echo "$@" | qrencode -s10 -o- | display

Check out the qrencode command line utility to learn about its parameters (thanks to my friend Matt for the heads-up about the -s parameter!). The display command is part of the ImageMagick suite. What is cool about display (and made my one-liner possible) is that it can read a png file from stdin.

It turns out that (unsurprisingly) I am not the first one to have this idea. Some people even decided that it would be great if a CLI tool to generate QR codes could output its result in a console (like this or that). Still, it is really cool that one can make a shell one-liner out of existing tools in under five minutes.

CategoryEnglish, CategoryBlog