Ubuntu – Notify-send only works with sudo

dbusnotify-osdnotify-sendpermissions

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.

Best Answer

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"
Related Question