Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement