How to intercept (kill) only specific notifications, using dbus-monitor
You can automatically kill specific messages if you have a specific identifying string, which occurres in the notification's text. In this case, "update" will probably do.
How to setup
Copy the script below into an empty file:
#!/bin/bash
string=$1
match="update"
if [[ $string == *$match* ]]
then
pkill notify-osd
fi
Save it as killnot.sh
. This will kill notify-osd
if a certain string occurres in the notification. Edit the line match="update"
to reflect the identifying string in the notification(s) you'd like to kill. Make the script executable.
Copy the script below into an empty file:
#!/bin/bash
scriptpath=/home/jacob/Bureaublad/killnot.sh
dbus-monitor "interface='org.freedesktop.Notifications'" | \
grep --line-buffered "string" | \
grep --line-buffered -e method -e ":" -e '""' -e urgency -e notify -v | \
grep --line-buffered '.*(?=string)|(?<=string).*' -oPi | \
grep --line-buffered -v '^\s*$' | \
xargs -I '{}' $scriptpath {}
Edit the line scriptpath=/home/jacob/Bureaublad/killnot.sh
to reflect the real path to script 1 (killnot.sh
) and save it as monitor_notifs.sh
. Make the script executable.
Test-run the setup by the command:
/path/to/monitor_notifs.sh
To test, run in another terminal the command:
notify-send <identifying_string>
The mesasage should not appear.
If all works fine, add it to your Startup applications: Dash > Startup Applications > Add. Add the command:
/path/to/monitor_notifs.sh
Notes / explanation
The script monitor_notifs.sh
uses dbus-monitor
in the same way as this answer. Running it in the background means nothing to your system and only triggers notifications.
These notifications, when they occur, are passed as an argument to the script killnot.sh
, which does nothing, unless the identifying string is in the notification's text. In that case it will kill notify-osd
.
With a little editing of the first script, you can make the setup kill notifications on multiple keywords at once.
EDIT only run the command until the bubble appears
If the notification only appears after log in, as you mention in your question, you can "smarten" the solution up to kill itself after it intercepted the update notificalion:
If you named the scripts in the setup exactly as indicated, add one line to the killnot.sh
sript:
pkill -P "$( pgrep -f run_intercept )"
The script then becomes:
#!/bin/bash
string=$1
match="update"
if [[ $string == *$match* ]]
then
pkill notify-osd
pkill -P "$( pgrep -f run_intercept )"
fi
The main script, run_intercept
, will then be killed after it did its job and you have no background script running anymore.
Closer to clean you cannot get in this situation imo.
killall notify-osd
to kill that one particular popup.gnome-software
thing. Happens all the time on Arch Linux with me, especially just after I'd upgraded packages usingpacman -Syu
.