Created
May 10, 2025 18:56
-
-
Save Amiralgaby/0b40d6781e8f07499480f757f823884a to your computer and use it in GitHub Desktop.
Décoder un QRCode en capturant une région d'un écran
This file contains hidden or 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 | |
zerr() { | |
zenity --error --text="$1" | |
} | |
command_exist() { | |
command -v "$1" > /dev/null | |
} | |
TMP_FILE="" | |
suppr_tempfile=0 | |
delete_tmpfile() { | |
[[ "$suppr_tempfile" -eq 1 ]] && rm "$TMP_FILE" | |
} | |
if ! command_exist zbarimg ; then | |
zerr "La commande zbarimg n'existe pas\n\ninstaller l'utilitaire via : sudo apt install zbar-tools" | |
exit 1 | |
fi | |
if [[ ! -f "$1" ]]; then | |
TMP_FILE="$(mktemp --suffix=.png)" | |
if command_exist gnome-screenshot; then | |
gnome-screenshot -a -f "$TMP_FILE" | |
elif [ "$XDG_SESSION_TYPE" = "x11" ] && command_exist xfce4-screenshooter; then | |
xfce4-screenshooter -r -s "$TMP_FILE" | |
elif command_exist spectacle; then | |
spectacle -r -o "$TMP_FILE" | |
else | |
zerr "Le script est implémenté pour ne fonctionner qu'avec les logiciels de capture d'écran suivant :\n- gnome-screenshot,\n- xfce4-screenshooter (avec le protocole X11),\n- spectacle.\n\nVeuillez installer un programme de capture d'écran parmi cette liste" | |
exit 1 | |
fi | |
# le fichier n'a pas été créé ou est vide | |
if [[ ! -f "$TMP_FILE" ]]; then | |
echo "le fichier n'existe pas ou est vide" | |
rm "$TMP_FILE" # il est vide, on le supprime | |
exit 2 | |
fi | |
suppr_tempfile=1 | |
set "$TMP_FILE" | |
fi | |
if ! RES=$(zbarimg --raw "$1" 2> /dev/null); then | |
delete_tmpfile | |
zerr "Aucun QRCode détécté" & | |
exit 0 | |
fi | |
delete_tmpfile | |
zenity --info --no-markup --text="$RES" --ellipsize & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment