notify-send仅适用于sudo

问题

sudo notify-send Test "Hello World" 

按预期显示通知。

 notify-send Test "Hello World" 

不显示通知。

更多的信息

Ubuntu版本16.04。

通知似乎使用notify-osd而不是notification-daemon。 运行notify-send似乎在运行notify-send的用户下启动notify-osd进程。 我不确定dbus是什么。

没有错误消息

syslog中没有错误。 当我运行以下代码时,不会出现错误消息。

 #include  #include  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; } 

我不知道我在做什么。 谢谢您的帮助。

Python通知

在过去,我使用了一个有工作通知的python程序。 我测试了一个hello world通知,它没有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() 

代码来自http://www.devdungeon.com/content/desktop-notifications-python-libnotify

我不知道为什么会这样。 python Notify只是包装C示例中使用的库。 我不想使用python但是如果必须的话。

编辑

问题再次发生。 通过添加紧急性来解决。

重新启动修复了问题。 不知道为什么。

编辑问题再次出现。 使用紧急关键导致通知出现。 命令是:

  notify-send --urgency="critical" "asdf" 

有了这个答案,我“修复”了这个问题。 现在不需要sudo 。 必须再次设置DBUS_SESSION_BUS_ADDRESS环境变量:

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

但是,正如这里所要求的 :

  • notify-send -u critical "Nice title" "Nice description"工作正常但是
  • notify-send -u normal "Nice title" "Nice description"不起作用。

同样使用-i这种方式似乎已弃用: notify-send -i "notification-network-wireless-full" "Summary" "Body" 。 也许我们应该提交一个bug 。