Created
January 20, 2012 21:14
-
-
Save gtmanfred/1649650 to your computer and use it in GitHub Desktop.
scan 2d and 3d barcodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Save this as a text file and make it executable. | |
# This script finds and decodes barcodes in a selection of the screen. | |
# Nice to have as a shortcut in your gnome-panel. | |
# When you run this script your pointer will change into a selection cursor | |
# and you then must select a portion of the screen to be analyzed. | |
# Results will be shown in a dialog window. | |
# Pass a number as the first argument to wait that number of seconds before | |
# invoking the screen capture command. | |
# This part checks for missing tools. | |
missing="" | |
which zbarimg >/dev/null || missing=${missing}" zbar-tools" | |
which import >/dev/null || missing=${missing}" imagemagick" | |
which zenity >/dev/null || missing=${missing}" zenity" | |
if [[ -n "${missing}" ]]; | |
then | |
echo "You seem to have some missing software that you'll need to install." | |
echo "If you're on a Debian system (or Ubuntu, Linux Mint or other derivatives), you probably can install all necessary software with the following command:" | |
echo "sudo apt-get install" $missing | |
echo | |
echo "Exiting..." | |
exit | |
fi | |
# This part waits the number of seconds passed in the first argument. | |
if [ 0 -lt "$1" ] 2>/dev/null; | |
then | |
sleep $1 | |
fi | |
# Capture a portion of the screen with ImageMagick's import and pass | |
# the resulting image to zbarimg for it to decode. | |
output="$(zbarimg <(import -))" | |
# Show the output in a window | |
# Also print to terminal, why not. | |
if [ -n "$output" ]; | |
then | |
zenity --info --text="$output" | |
printf "%s\n" "$output" | |
else | |
zenity --info --text="Nothing found." | |
echo "$0: Nothing found." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment