Arch Linux: уведомления в Openbox с libnotify

Автор: | 23/08/2017
 

Надо добавить всплывающее окошко, которое бы по крону выводило какой-то текст на экран.

Используем libnofity, выполняем на Arch Linux (хотя принципиальной разницы нет – хоть на Убунте).

Документация самого libnotify – тут>>>.

Установка

Устанавливаем libnotify:

[simterm]

$ sudo pacman -S libnotify

[/simterm]

И notification-daemon:

[simterm]

$ sudo pacman -S notification-daemon

[/simterm]

Либо notify-osd:

[simterm]

$ sudo pacman -S notify-osd

[/simterm]

Запускаем демон:

[simterm]

$ /usr/lib/notification-daemon-1.0/notification-daemon &

[/simterm]

Добавляем в автостарт:

[simterm]

$ echo "/usr/lib/notification-daemon-1.0/notification-daemon &" >> /home/setevoy/.config/openbox/autostart

[/simterm]

Проверяем:

[simterm]

$ notify-send 'Hello world!'

[/simterm]

Иконки

Что бы добавить иконку к сообщению – используем -i.

Например – иконки из Arc темы:

[simterm]

$ ls -l /usr/share/icons/Arc/apps/128
total 96
lrwxrwxrwx 1 root root    30 Nov 24  2016 activity-log-manager.png -> preferences-system-privacy.png
lrwxrwxrwx 1 root root    13 Nov 24  2016 blueman.png -> bluetooth.png
lrwxrwxrwx 1 root root    13 Nov 24  2016 blueradio-48.png -> bluetooth.png
lrwxrwxrwx 1 root root    13 Nov 24  2016 blueradio.png -> bluetooth.png
...

[/simterm]

Вызываем notify-send и указываем путь к иконке:

[simterm]

$ notify-send -u critical -i '/usr/share/icons/Arc/apps/128/system-users.png' 'Hello, World' 'Other'

[/simterm]

И уведомления в трее:

Примеры

bash

Свамй простой скрипт на bash будет выглядеть так:

#!/usr/bin/env bash

notify-send 'Hello world!' 'This is an example notification.' --icon=dialog-information

Вызываем:

[simterm]

$ bash .opt/notify.sh

[/simterm]

При необходимости – добавляем в cron (добавив $DBUS_SESSION_BUS_ADDRESS).

C

#include <libnotify/notify.h>

int main() {

    notify_init ("Hello world!");

    NotifyNotification * Hello = notify_notification_new ("Hello world", "This is an example notification.", "dialog-information");
    
    notify_notification_show (Hello, NULL);
    
    g_object_unref(G_OBJECT(Hello));
    
    notify_uninit();
    
    return 0;
}

Собираем:

[simterm]

$ gcc -o notify `pkg-config --cflags --libs libnotify` notify.c

[/simterm]

Выполняем:

Ссылки по теме

How To Send Desktop Notifications on Ubuntu Using notify-send