To intercept (notify-osd) notifications on Linux (Ubuntu), I am using the dbus-monitor script below. Subsequently, the script runs another script (/opt/nonotifs/nonotifs/silent) with the intercepted notification as argument, for further processing:
#!/bin/bash
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 '{}' /opt/nonotifs/nonotifs/silent {}
This works flawlessly, except with notifications by hplip.
When run from a terminal, the script above shows:
xargs: unmatched double quote; by default quotes are special to xargs unless you use the -0 option
When using the option -0 however, the script delivers no argument at all.
What I tried
In some cases, the script subsequently breaks. If that would always be the case, It could be worked around by running it in a "keep alive" -wrapper, which I tried. Often however, The script does not terminate, but it stops returning the intercepted notifications nevertheless.
How can I solve this?
Edit
As suggested by @Serg, I replaced the xargs... section by cat -A, to see what is passed to xargs. This shows that indeed there is an unmatched double quote in the notification of hplip (the third line), which seems to be a bug in the notification.
The output when running with cat -A, calling the notification:
"hplip"$
"HPLIP Device Status"$
"Officejet_Pro_8600$
"transient"$
cat -Ainstead ofxargsthere – Sergiy Kolodyazhnyy Oct 28 '16 at 20:37"hplip"$ "HPLIP Device Status"$ "Officejet_Pro_8600$ "transient"$, which indeed shows an unmatched double quote (in"Officejet_Pro_8600$) – Jacob Vlijm Oct 28 '16 at 20:46"Officejet_Pro_8600$- an incorrect notification... – Jacob Vlijm Oct 28 '16 at 20:52tr -d '"'to delete the double quotes ? – Sergiy Kolodyazhnyy Oct 28 '16 at 20:55tr -d '"'is used to delete specific characters. So , you want to place it between lastgrepandxargsso , trygrep --line-buffered -v '^\s*$' | tr -d '"' | xargs . . . .Not ideal solution, of course, but at least you don't have to deal with unmatched double quotes then – Sergiy Kolodyazhnyy Oct 28 '16 at 21:07