introduction
Le script ci-dessous permet de couper toutes les notifications d'apparaître à l'écran. Il existe deux options de base -mpour désactiver et -uréactiver le son. Les deux sont regroupés dans un .desktopfichier pour servir de lanceur.
Quand -mest utilisé, le notifier-osd enverra une notification finale avant d'être bloqué. S'il y a une autre instance de script en cours d'exécution, il affichera une fenêtre contextuelle graphique qui informera un utilisateur que le script fait déjà son travail.
Lorsqu'il est appelé avec -uoption, le script arrêtera de bloquer les notifications et le confirmera en en affichant une. Si aucune instance précédente de script n'est en cours d'exécution, l'utilisateur sera informé que rien n'est bloqué pour le moment.
Source de script
La source du script est disponible ici. Pour une version plus à jour, vous pouvez toujours le trouver sur mon github . Vous pouvez installer git avec sudo apt-get install gitet cloner l'ensemble du référentiel avec git clone https://github.com/SergKolo/sergrep.gitou utiliser
wget https://raw.githubusercontent.com/SergKolo/sergrep/master/notify-block.sh  && chmod +x notify-block.sh
pour obtenir juste le script lui-même.
#!/usr/bin/env bash
#
###########################################################
# Author: Serg Kolo , contact: 1047481448@qq.com 
# Date: May 10th 2016
# Purpose: Notification blocker for Ubuntu
# Written for: 
# Tested on:  Ubuntu 14.04 LTS
###########################################################
# Copyright: Serg Kolo ,2016 
#    
#     Permission to use, copy, modify, and distribute this software is hereby granted
#     without fee, provided that  the copyright notice above and this permission statement
#     appear in all copies.
#
#     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
#     THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
#     DEALINGS IN THE SOFTWARE.
ARGV0="$0"
ARGC=$#
mute_notifications()
{ 
  self=${ARGV0##*/}
  CHECK_PID_NUMS=$(pgrep -f  "$self -m" | wc -l )
  if [ "$CHECK_PID_NUMS" -gt 2 ]; then
     zenity --info --text "Notifications already disabled"
     exit 0
  else  
     killall notify-osd 2> /dev/null # ensure we have PID
     notify-send 'All notifications will be muted after this one' 
     sleep 1
     while true 
     do 
        PID=$(pgrep notify-osd)
        [  "x$PID" != "x" ]  && 
        kill -TERM $PID 
        sleep 0.25
     done
  fi
}
unmute()
{
  echo $0
  self=${0##*/}
  MUTE_PID=$(pgrep -f  "$self -m" ) #match self with -m option
  if [ "x$MUTE_PID" != "x"   ];then
     kill -TERM "$MUTE_PID" &&
     sleep 1 && # ensure the previous process exits
     notify-send "UNMUTED"
     exit 0
  else 
     notify-send "NOTIFICATIONS ALREADY UNMUTED"
     exit 0
  fi  
}
print_usage()
{
  cat > /dev/stderr <<EOF
  usage: notify-block.sh [-m|-u]
EOF
exit 1
}
main()
{
  [ $# -eq 0  ] && print_usage
  while getopts "mu" options
  do
     case ${options} in
          m) mute_notifications & ;;
          u) unmute ;;
          \?) print_usage ;;
     esac
  done
}
main "$@"
modèle de raccourci .desktop
Ceci est juste un exemple de ce que j'utilise personnellement. Remplacez chaque Exec=ligne par le chemin d'accès approprié au script dans votre environnement. Bien sûr, vous Icon=devrez également changer. De préférence, conservez ce fichier dans votre ~/.local/share/applicationsdossier
[Desktop Entry]
Name=Notification Blocker
Comment=blocks any on-screen notifications
Terminal=false
Actions=Mute;Unmute
Type=Application
Exec=/home/xieerqi/sergrep/notify-block.sh -m
Icon=/home/xieerqi/Desktop/no-notif2.png
[Desktop Action Mute]
Name=Mute Notifications
Exec=/home/xieerqi/sergrep/notify-block.sh -m
Terminal=false
[Desktop Action Unmute]
Name=Unmute Notifications
Exec=/home/xieerqi/sergrep/notify-block.sh -u
Terminal=false
Captures d'écran

Le fichier de raccourci verrouillé sur le lanceur

Notification finale avant l'inhibition