qrencode — generate ASCII QR codes in macOS terminal

You are here:

QR Codes are a great way to share information with other devices. Typically, QR Codes are images, but thanks to a great open source project called qrencode, you can easily generate ASCII QR Codes to share information right from the terminal.

The project itself links against libpng and its own library; I compiled it statically so it doesn’t require any external dependencies. You can download the compiled tool here and read more about it here. Here are some interesting things you can do with it:

Show a URL

./qrencode -t ANSI -o - "https://twocanoes.com"

Generate a dad joke in a qrcode

curl -H "Accept: text/plain" https://icanhazdadjoke.com/ | ./qrencode  -t ANSI

Show a QR Code of whatever you last copied

pbpaste | ./qrencode -t ANSI

Show a QR code of the current Mac system information

model_id=$(sysctl -n hw.model) 
	cpu=$(sysctl machdep.cpu.brand_string | sed "s/.*: \(.*\)/\1/g"|sed "s/Intel.*(TM) //g"| sed "s/ CPU @ /-/g") 
	hardware_memory=$(($(sysctl -n hw.memsize)/1024/1024/1024))
	first_physical_disk_size=$(diskutil list physical|grep 'GUID_partition_scheme'| head -1 |sed "s/.*GUID_partition_scheme.*\([0-9]\{1,\}\.[0-9]\{1,\}.*[a-z|A-Z]\{1,\}\).*disk.*/\1/g")
	mac_info=$(echo $model_id \| $cpu \| $hardware_memory GB \| $first_physical_disk_size )
	echo $mac_info
	# sample output: MacBookPro16,1 | i9-9880H-2.30GHz | 16 GB | 1.0 TB
	echo $mac_info | ./qrencode -t ANSI

Smart Card Utility Beta

Sign up to receive information about Smart Card Utility Beta and related news. Once you confirm your subscription, a link will be sent to download the current beta via TestFlight.