Ubuntu – notify-osd replaced with dunst after switching back to unity from i3wm

notificationnotify-osdunity

I was testing i3wm (sudo apt-get install i3 is what I ran, and chose i3 from the log in screen) on my machine and after a while, decided to switch back to Unity. Upon switching back, I noticed that notifications came in the top right corner similar to i3 even though I was using Unity.

I'd really like it to use the normal Unity notification bubbles instead.

I looked into it and turns out instead of notify-osd, dunst is being used.

I tried using sudo vim /usr/share/dbus-1/services/org.freedesktop.Notifications.service and editing the file, but it has the correct line (i.e. Exec=/usr/lib/x86_64-linux-gnu/notify-osd) as expected.

I also tried unity-tweak-tool --reset-unity but that didn't do anything.

Is it possible for me to return to the normal notifications? Any help would be greatly appreciated. Thanks 🙂

Edit: I was able to return to the normal notifications by removing i3wm itself (and dunst). What I am actually asking is: is it possible to change to normal notifications while still keeping i3 and dunst on my system?

Note: This is NOT a duplicate of Notify-osd notifications appear unthemed in top-left corner. The solution there is to remove dunst and I would like to keep dunst and have that work when I choose i3, and have notify-osd work when I choose Unity.

Best Answer

I realize I'm two years late to the party, but if anyone else encounters this problem, here's a solution that will use notify-osd when logged into Unity, and dunst when running i3.

If you just want to keep dunst installed, but not auto-invoke it via DBus skip to the Quick Hack section.

Dunst in i3, notify-osd in Unity

Step 1

We want to override the behaviors of /usr/share/dbus-1/services/org.freedesktop.Notifications.service and more importantly /usr/share/dbus-1/services/org.knopwob.dunst.service.

Since Dbus looks at $XDG_DATA_HOME when searching for service files, and Ubuntu for some reason doesn't set that environment variable, we need to do it ourselves:

echo 'export XDG_DATA_HOME=${XDG_DATA_HOME:="$HOME/.local/share"}' >> ~/.profile 

Step 2

We need to create our service file:

mkdir -p $HOME/.local/share/dbus-1/services
nano $HOME/.local/share/dbus-1/services/usernotify.service

Make the file look like this:

[D-BUS Service]
Name=org.freedesktop.Notifications
Exec=/usr/bin/my_notifier

Step 3

Create the script referred to in your D-BUS file that invokes dunst if i3 is running, otherwise notify-osd:

sudo nano /usr/bin/my_notifier

Make it look like this:

#!/bin/bash
set -euo pipefail
if pgrep -x i3 >/dev/null; then
    /usr/bin/dunst
else
    /usr/lib/x86_64-linux-gnu/notify-osd
fi

Make it executable:

sudo chmod a+x /usr/bin/my_notifier

Step 4

That should be it. Log out and then log in again. Test it in both Unity and i3 by running

notify-send foo bar

Quick Hack

If you exclusively want to use notify-osd it's enough to edit /usr/share/dbus-1/services/org.knopwob.dunst.service accordingly:

[D-BUS Service]
Name=org.freedesktop.Notifications
#Exec=/usr/bin/dunst
Exec=/usr/lib/x86_64-linux-gnu/notify-osd