dunst-project / dunst

Lightweight and customizable notification daemon
https://dunst-project.org
Other
4.44k stars 338 forks source link

How exactly to disable any notification for a specific program #1239

Closed c02y closed 7 months ago

c02y commented 7 months ago

Issue description

I need to disable any notification for a specific program (fcitx5), but I don't know how, the doc or man doesn't show any useful info

Installation info

Minimal dunstrc All the same as `/etc/dunst/dunstrc` except for the following ```ini [ignore] desktop_entry = "org.fcitx.Fcitx5" skip_display = true ```

BTW:

$ dunst -print
CRITICAL: [dbus_cb_name_lost:1152] Cannot acquire 'org.freedesktop.Notifications': Name is acquired by 'dunst' with PID '205305'.
bynect commented 7 months ago

You simply have to create a rule in dunstrc matching the program name and hiding the notification. When I am home I'll add more info.

Anyway, the error you are getting is simply because a dunst instance is already running.

bynect commented 7 months ago

There was a very similar question here #1024

c02y commented 7 months ago

Yes, I searched before this issue,

You can use dunst -print to see what app name or other matching rules you can use.

BUT

$ dunst -print
CRITICAL: [dbus_cb_name_lost:1152] Cannot acquire 'org.freedesktop.Notifications': Name is acquired by 'dunst' with PID '205305'.

So, what should I do?

maxz commented 7 months ago

Kill your running dunst process first and then start a new one with dunst -print.

c02y commented 7 months ago

@maxz thanks, every time I modify my dunstrc, I will kill dunst and start new dunst session (since dunst doesn't have a auto reload rc feature), but dunst -print always outputs the similiar error message.

maxz commented 7 months ago

That should no happen. Maybe something on your system automatically restarts dunst when the process is killed. (e. g. Systemd or some other process supervisor)

See which PID is output when running dunst -print and then try running kill $PID && dunst -print. If that does not work and an instance of dunst is already running at that point you will have to find out how dunst is restarted and disable that temporarily. Replace $PID by the PID which dunst -print refers to.

Maybe worth mentioning: dunst -print is not a way to communicate with a running dunst daemon. It is a way of starting a dunst daemon.

c02y commented 7 months ago

I never see dunst is restarted automatically in my system, since usually after I kill dunst process, I would check if it is really killed.

I use dunst -print because, in /etc/dunst/dunstrc, it says

# NOTE: It might be helpful to run dunst -print in a terminal in order
# to find fitting options for rules.

since I cannot find any doc saying how can I get appname/summary/body/desktop_entry/..., I thought it would be listed in the output of dunst -print

image

maxz commented 7 months ago

You try to start dunst twice. Do what I wrote, e. g. use dunst -config /home/chz/.config/i3/dunstrc -print in your case to start it.

c02y commented 7 months ago

OK, thanks, didn't know dunst -print is to start dunst session, the following doc may be incorrect.

# NOTE: It might be helpful to run dunst -print in a terminal in order
# to find fitting options for rules.

Besides, dunst -print command prints nothing unless it receives a notification from some program.

So back to the original question, what should I do to disable any notification for a specific program?


UPDATE: I managed to get the appname for the program I need by manually triggering a notificaiton from the specific program, then I wrote the appname from the outout of dunst -print into the dunstrc, it seems works.

Is there any way that I can get the appname or other useful rule without waiting for the notification or triggering the notificaiton manually?

maxz commented 7 months ago

Is there any way that I can get the appname or other useful rule without waiting for the notification or triggering the notificaiton manually?

That is the safest way.

There is no other surefire way. appname and desktop_entry are not mandatory fields (they could be the empty string.)

Otherwise going by the desktop_entry would be the best way. I'm not sure how the desktop entry that you now found via dunst -print and the one you previously specified in your dunstrc differ, but you might be able to derive something there.

Obviously filtering by body or summary might also work perfectly fine, depending on your case. Personally I never had a case where I wanted to filter by appname.

c02y commented 7 months ago

desktop_entry I got is from Goggle, it is said to be the name of desktop file in the system, since I didn't how how to get the rules back then.

But I noticed that desktop_entry entry in the dunst -print result for the program I need is empty.

Anyway, thank you.