3

I wonder if there is any command line method to make notifications in Ubuntu notification bubble. Or is there a file that belong to this task?
I want the following characteristics:

  • My own messages appear in the notification bubble.
  • These notifications appear in a specific position on the screen, not only in the default position.
  • The size of notification bubble can be changed.
  • Its color can be changed.

UPDATE

I read "How can I send a custom desktop notification?" and now, I know that notify-send will help me in my purpose. But there is some limitations with this command. I want to know whether there is any other command to use, or any file to change, so that size,color and position of notification bubble can be changed?

  • The basic tool for notifications is notify-osd. There's a simplified alias for bash defined by default in your .bashrc file called alert. But they do not fulfil most of your requirements. – Byte Commander Sep 19 '15 at 16:41
  • libnotify has a binary called notify-send. The basic usage is notify-send "title" "message body". You can use notify-send --help for more options, but it doesn't have options for notification color or position. (You can set the icon, urgency, timeout, and a couple other options though.) – Yamaho Sep 19 '15 at 16:46
  • Hi mohammed. I will vote to reopen. I am afraid only to hear that there is no such thing, but you made the question different enough to exist. – Jacob Vlijm Sep 21 '15 at 18:36
  • GNOME or Unity or something else? – A.B. Sep 23 '15 at 5:28
  • @ A.B. : Gnome. – Mohammad Sep 23 '15 at 5:31
6

Historically, there were different approaches to problem of "notifications". There isn't even consensus of what "notification" is. Do we use it to only tell user that something happened? Do we expect any action from him? If so, how is input gathered? Can that action be delayed, or should user act immediately? How long could it be delayed? How is user supposed to review all pending actions? Answers to all these questions shape solutions proposed by different teams.

The bottom line is, there is no single, definite answer to your question. But there are different approaches that you can try and pick one that fits your particular use-case.

notify-send

At one point, a standard for notifications on Linux emerged. The driving force behind it, if memory serves me right, was GNOME 3 team. They strove for unified way for all applications to notify user and figured out that some component of desktop environment should be responsible for handling (queuing, displaying, gathering input) all notifications. Applications merely send their notification to that component and hope that user receive it.

You can create that kind of notification with notify-send command line app. Note that it purposeful does not allow for customization. You only pass your message and leave the rest to desktop environment. This kind of notifications is supported by Unity (Ubuntu), GNOME 3 and KDE SC/Plasma.

osd_cat

osd_cat is application that displays content of file on X server layer. By using -d switch, you can make it automatically disappear after some time, which makes it somewhat suitable as notification app.

The default font will be ugly, but you can make it better by using -f switch. -f argument must be string constructed by xfontsel.

A sample notification could be created this way:

echo -e "sample\nnotification" |osd_cat -p middle -A center -d 1 -f '-*-helvetica-*-r-*-*-34-*-*-*-*-*-*-*' -O 1 -c '#fff'

Contrary to notify-send, you can place your notification anywhere on the screen and you can customize it a bit (select font and color; there is no background color). The main drawback is that it is X-specific, so it will not work under Mir or Wayland.

zenity/kdialog

zenity (for GTK desktops - Unity and GNOME) and kdialog (for Qt desktops - KDE and LxQt) allow user to create simple dialog windows from command line. You can put text inside, but also some predefined icons, buttons, input forms, lists, file pickers or progress bars. With a little work on your side, you could use them as a way to notify user.

zenity supports --width= and --height= command line switches, but doesn't provide any way to change placement of window. Personally, I am using --title= to give window some custom title and window manager rules. Window manager (KWin in my case) picks all windows that match certain criteria, like title containing string, and modify their properties. For notifications I put these windows in lower right corner of screen, remove window title bar, make them appear on all virtual desktops and remove them from task bar.

Custom solution

If neither of above programs suits your requirements, you can always write your custom solution. python provides bindings to both GTK and Qt and will allow you to relatively painlessly create custom GUI. You will have all the customization options in the world, but this will require some initial work to get started.

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.