10

Ubuntu has a very cool notification system. Is there a way to make Ubuntu read out notifications when they appear?

Or is it possible to link the text in notifications to espeak?

Saurav Kumar
  • 14,916
Meow
  • 1,357
  • This https://bugs.launchpad.net/ubuntu/+source/notify-osd/+bug/345357 states orca did not and now does again(?) – Rinzwind Oct 30 '13 at 18:57
  • 1
    orca reads everything and is very annoying what am looking for is a way to read only the notifications anyway thanks for the support :) – Meow Oct 30 '13 at 19:21

2 Answers2

18

This question is really interesting so as the answer.

dbus-monitor when executed waits for the signal and when arrives it catches and gives the appropriate information about it. Similarly it can be executed to get the info about Notifications. When executed:

dbus-monitor "interface='org.freedesktop.Notifications'" | grep --line-buffered "member=Notify\|string"

It will wait for the notifications and when any notification arrives it gives the information of the notifications.

For example when sound is increased/decreased or any song track is changed or any other it gives the message. I'm manually creating a desktop notification using notify-send command on any other terminal:

notify-send "Hello How are you?"

Then the first terminal in which dbus-monitor command is executing will give message like:

saurav@saurav-P4I45Gx-PE:~$ dbus-monitor "interface='org.freedesktop.Notifications'" | grep --line-buffered "member=Notify\|string"
   string ":1.473"
method call sender=:1.474 -> dest=:1.475 serial=7    path=/org/freedesktop/Notifications; interface=org.freedesktop.Notifications;  member=Notify
   string "notify-send"
   string ""
   string "Hello How Are You?"
   string ""
         string "urgency"

Now above output can be easily passed to espeak to read message. For example,

Replacing the above dbus-monitor command with following will read the notification message:

Check, How does it work:

  • Execute this command in a terminal and leave it running:

    dbus-monitor "interface='org.freedesktop.Notifications'" | grep --line-buffered "string" | grep --line-buffered -e method -e ":" -e '""' -e urgency -e notify -v | grep --line-buffered '.*(?=string)|(?<=string).*' -oPi | grep --line-buffered -v '^\s*$' | xargs -I '{}' espeak {}
    

    I know it has become very long, but there is no other way to make it small because the filtering of actual notification made it lengthy.

  • Then run a desktop notification either the way I described above using notify-send or any thing else. I'm using notify-send. So executing following command in other terminal:

    notify-send "Hello! I am Saurav Kumar."
    

    As soon as you execute the command it will speak(read) the notification.

Although it ate my 4-5 hours, but I'm happy now to make it working.

You can also make your own command like saynoti and execute it every time you want a reading notification. By following these steps you can do so:

  • First save the actual command to a file called saynoti. You can use any file name that will become your actual command name.

  • Then make the file executable and move or copy it to /bin:

    chmod +x saynoti
    sudo cp saynoti /bin
    
  • Now you can simply execute your new command to start Speaking Notification:

    saynoti
    
  • To kill the running process you can execute this command:

    pkill dbus-monitor
    

    or simply press Ctrl + C on the terminal where saynoti is running.

  • You can also run saynoti every time your system starts by making it a start-up application.

I would like to say thank you for this question. Because of this question, I learned a lot of things. :)

Reply if you get any problem or need any further change/modification. I'm sure you will be happy to get the final working version.

Saurav Kumar
  • 14,916
  • @Meow: Sounds good that you're pleased with the outcome. In future if you'll need any modification, just ping me here. – Saurav Kumar Oct 31 '13 at 10:19
  • @Meow: Check the final working version. I solved all the issue and it is working great. You will be happy to get this version. – Saurav Kumar Oct 31 '13 at 17:38
  • 2
    dude u'r awesome can't ask anything else; i placed it in my startup list and it works flawlessly merci beaucoup – Meow Nov 01 '13 at 08:38
  • from where did you learn about dbus-monitor, I want to start learning – Alex Jones Nov 06 '15 at 15:15
  • @edwardtorvalds: You can learn it from its official site about Dbus and Dbus-Monitor.
    1. http://www.freedesktop.org/wiki/Software/dbus/
    2. http://dbus.freedesktop.org/doc/dbus-monitor.1.html
    – Saurav Kumar Nov 11 '15 at 07:01
0

I had troubble with extra " in my email addresses hence I have added this to the code line above as espeak needs no " at all to read out ;)

| sed 's/\"//g' |

=>

| grep --line-buffered -v '^\s*$' | sed 's/\"//g' | xargs -I '{}' espeak {}

COOL work. Better by far than tweaking notify-send lib itself 4 "Hello! I am Saurav Kumar."

update: does not work steady. I will use | tee -a $file |

Jimmy
  • 1