2

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.

  • 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 6 '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 6 '16 at 18:57
  • Did the issue by any chance start when you ran the command sudo notify-send...? – Jacob Vlijm Sep 6 '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 6 '16 at 19:07
  • Restarting the computer has fixed the problem. Notify-send now no longer requires sudo. Thanks for the help. – aco Sep 6 '16 at 19:09
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"
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.