3

Problem

sudo notify-send Test "Hello World"

Displays a notification as expected.

notify-send Test "Hello World"

Does not display a notification.

Further information

Ubuntu version 16.04.

The notifications appear to use notify-osd instead of notification-daemon. Running notify-send appears to launch a notify-osd process under the user that ran notify-send. I'm not sure what dbus is.

No error messages

There are no errors in the syslog. When I run the following code no error messages occur.

#include <libnotify/notify.h>
#include <stdio.h>
int main() {
    gboolean x = notify_init ("Hello world!");
    printf( "notify_init: %d\n", x );
    NotifyNotification * Hello = notify_notification_new ("Hello world", "This is an example notification.", "dialog-information");
    GError *err = NULL;
    x = notify_notification_show (Hello, &err);
    printf( "notify_notification_show: %d\n", x );
    if(err != NULL) {
        printf("Error detected!\n");
        printf("Error message:%s\n", err->message);
    }
    else {
        printf("No error detected.\n");
    }
    g_object_unref(G_OBJECT(Hello));
    notify_uninit();
    return 0;
}

I do not know what I'm doing. Thanks for the help.

Python Notify

In the past, I've used a python program that has working notifications. I tested a hello world notification and it works without sudo!

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import gi
gi.require_version('Notify', '0.7')
from gi.repository import Notify

Notify.init("test")
n = Notify.Notification.new('test', 'test2')
n.set_urgency(Notify.Urgency.CRITICAL)    
n.show()

Code from http://www.devdungeon.com/content/desktop-notifications-python-libnotify

I am not sure why this works. The python Notify is just wrapping the library used in the C example. I'd prefer not to use python but will if I must.

Edit

The problem occurred again. Resolved by adding urgency critical.

aco
  • 51
  • Is there another user account on your system to check if it is also on other users? Another question: did notifications work fine in the past on this account, also from cli? – Jacob Vlijm Sep 06 '16 at 18:43
  • No there isn't another desktop user. I can add one and check. This is my first time using notifications but volume control and a bunch of other ubuntu built-ins display notifications. Add python test to post. – aco Sep 06 '16 at 18:57
  • Did the issue by any chance start when you ran the command sudo notify-send...? – Jacob Vlijm Sep 06 '16 at 18:59
  • No. I'm pretty sure I ran notify-send first. Then decided to try sudo because then the computer knows I really mean it. – aco Sep 06 '16 at 19:07
  • Restarting the computer has fixed the problem. Notify-send now no longer requires sudo. Thanks for the help. – aco Sep 06 '16 at 19:09
  • I am not sure I was of any help :), but great that it is fixed :) – Jacob Vlijm Sep 06 '16 at 19:10
  • Andrew, maybe we should close it as not reproducable? – Jacob Vlijm Sep 06 '16 at 19:13
  • You can do that! – aco Sep 06 '16 at 19:15
  • I need at least 300 reputation to add the "close" tag. I'll just accept the answer below. I tried breaking it again by running sudo and another custom notification program but no luck. – aco Sep 06 '16 at 19:19
  • Don't worry, it will get closed over time if a few more people see it. Don't delete, it is a waste of your + 5, and the question is well- documented. – Jacob Vlijm Sep 06 '16 at 19:21
  • I'm leaving it just in case some one else runs into it. Wasted a couple hours trying to figure this out :( – aco Sep 06 '16 at 19:22
  • Occasionally , notifications can get blocked (for whatever reason), so in that case you can try setting urgency level. notify-send --urgency="critical" "Hello" "World". – Sergiy Kolodyazhnyy Sep 06 '16 at 20:53
  • I have the same problem on same setup and reboot doesn't fix it. A bash script I use regularly use it and someday stop working. I check /usr/bin/notify-send permissions and are OK (755). Also tried purge/install. Command end silently with exit status code 0. Urgency level don't change anything. libnotify-bin v0.7.6-2svn1, notify-osd v0.8+15.10.20151016.2. – Pablo Bianchi Jul 15 '17 at 19:00

2 Answers2

1

Restarting fixed the problem. Not sure why.

Edit The problem occurred again. Using urgency critical caused the notification to appear. The command is:

 notify-send --urgency="critical" "asdf"
aco
  • 51
0

With this answer I "fixed" the problem. No sudo needed now. Have to set again DBUS_SESSION_BUS_ADDRESS environment variable:

eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)";

But, as asked here:

  • notify-send -u critical "Nice title" "Nice description" work fine but
  • notify-send -u normal "Nice title" "Nice description" doesn't work.

Also using -i this way seems deprecated: notify-send -i "notification-network-wireless-full" "Summary" "Body". Maybe we should file a bug.

Pablo Bianchi
  • 15,657