#!/bin/bash ### Variables Customisables. Icon_Off="/chemin/de/l'image/ON" # À adapter. Icon_On="/chemin/de/l'image/OFF" # " " Switch="$HOME/systray_switch_state" # " " Fichier d'état (contient soit ON soit OFF). ### Fonctions. _quit () { local s="inotifywait -qme close_write ${Switch//\//\\\\/}" kill -15 "$(ps -ef | awk -vs="$s" '$0 ~ s && !/awk/{print $2}')" } _switch () { local etat etat=$(<"$Switch") if [ "$etat" = "ON" ] echo "OFF" >"$Switch" # # Code ICI pour les actions OFF (optionnel) # else echo "ON" >"$Switch" # # Code ICI pour les actions ON (optionnel) # fi } _icon_set () { local etat icon while read -r do etat=$(<"$Switch") [ "$etat" = "ON" ] && icon="$Icon_On" || icon="$Icon_Off" echo "icon:$icon" done < <(echo; inotifywait -qme close_write "$Switch") } ### Export (Variable et Fonctions). export Switch export -f _quit _switch exec 2>/dev/null # Pour éviter le message `Complété` à la fermeture de yad par la fonction `_quit`. ### Notification YAD (icône systray). # text = affiché au survol de la souris # menu = affichage+action(si clic) du menu sur clic droit de la souris # command = switch direct sur clic gauche de la souris yad --notification \ --text "Texte de la bulle au survol de la souris" \ --icon-size 64 \ --no-middle \ --menu "Switcher!bash -c '_switch'|Quitter!bash -c '_quit'" \ --command "bash -c '_switch'" \ --listen < <(_icon_set)