If you have a need to catalog items, be they for inventory of a store, or for assets of a business, you might find yourself needing to create some sort of barcode option for your items. Granted there are a number of well-established software packages for doing so, but at times you may create custom scripts, out of which you might want a QR or data matrix code to be generated.
Since we’re talking about scripting here, this means using tools other than Web sites, or desktop databasing and inventorying software that can take input in a field and generate a desired barcode or other symbolic representation.
- Go to htp://brew.sh
- Copy the install command listed on the site
- Open the Terminal utility and paste the command
- Execute the command, and follow the on-screen instructions
Now you can use Homebrew to install the tools for creating QR and data matrix codes:
- Run the following command to install QR generation tools:
brew install qrencode
- Run the following command to install data matrix management utilities:
brew install libdmtx brew install dmtx-utils
With these installed, you can now generate QR and data matrix codes in the Terminal, and thus can do so in scripts you create, by piping output from other commands and scripts to these tools. For example, to create a basic QR code that points a Web browser to this Web site, you could run the following command:
echo "http://www.macissues.com" | qrencode -o ~/Desktop/MacissuesQR.png
After running your command, the following QR code will be on your desktop, that you can scan with a number of QR readers, and be brought to this Web site.
For data matrix codes, the process is simpler, where a command such as the following can be used to encode the given text:
echo "to be encoded" | dmtxwrite -s s -o ~/Desktop/encodedDM.png
The output of this command should be an image that looks like the following:
For these two commands, the image files will be on your desktop. You can use additional flags and options for changing the type of code, the size, colors, and other options that may be specific for your needs. To get more details on what you can do with these two encoders, run these two commands with the “–help” flag, or access their respective man pages.