Advertisement
Guest User

Decode barcodes visible on a portion of your screen.

a guest
Jan 20th, 2012
1,650
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.61 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Save this as a text file and make it executable.
  4.  
  5. # This script finds and decodes barcodes in a selection of the screen.
  6. # Nice to have as a shortcut in your gnome-panel.
  7.  
  8. # When you run this script your pointer will change into a selection cursor
  9. #  and you then must select a portion of the screen to be analyzed.
  10.  
  11. # Results will be shown in a dialog window.
  12.  
  13. # Pass a number as the first argument to wait that number of seconds before
  14. #  invoking the screen capture command.
  15.  
  16.  
  17. # This part checks for missing tools.
  18.  
  19. missing=""
  20.  
  21. which zbarimg >/dev/null || missing=${missing}" zbar-tools"
  22. which import >/dev/null || missing=${missing}" imagemagick"
  23. which zenity >/dev/null || missing=${missing}" zenity"
  24.  
  25. if [[ -n "${missing}" ]];
  26. then
  27.     echo "You seem to have some missing software that you'll need to install."
  28.     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:"
  29.     echo "sudo apt-get install" $missing
  30.     echo
  31.     echo "Exiting..."
  32.     exit
  33. fi
  34.  
  35. # This part waits the number of seconds passed in the first argument.
  36.  
  37. if [ 0 -lt "$1" ] 2>/dev/null;
  38. then
  39.     sleep $1
  40. fi
  41.  
  42. # Capture a portion of the screen with ImageMagick's import and pass
  43. #  the resulting image to zbarimg for it to decode.
  44.  
  45. output="$(zbarimg <(import -))"
  46.  
  47. # Show the output in a window
  48. # Also print to terminal, why not.
  49.  
  50. if [ -n "$output" ];
  51. then
  52.     zenity --info --text="$output"
  53.     printf "%s\n" "$output"
  54. else
  55.     zenity --info --text="Nothing found."
  56.     echo "$0: Nothing found."
  57. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement