Mastodon

Fun with Ubuntu’s notifications in Ruby

Ubuntu has a pretty snazzy notification system and, as it turns out, its really easy to use it in your scripts. At its core is libnotify, which is already somewhere on each Ubuntu system. To talk to it in your Ruby scripts you need to install the bindings for Ruby and the gem.

sudo aptitude install libinotify-ruby libgtk2-ruby libnotify-dev;

And then:

sudo gem install libnotify

Once thats done, fire up IRB:

irb(main):018:0> require ‘date’
=> true
irb(main):019:0> require ‘rubygems’
=> true
irb(main):020:0> require ‘libnotify’
=> true
irb(main):021:0>Libnotify.show :summary => “#{Date.today}”, :body => “Happy #{Date::DAYNAMES[Date.today.wday]}!”
=> true

The “require ‘date'” is only there because IRB doesn’t seem to include Date (or doesn’t include all of  it) for some reason. The result:

How awesome is that?

One thought on “Fun with Ubuntu’s notifications in Ruby”

Leave a Reply

Discover more from mikewilliamson.dev

Subscribe now to keep reading and get access to the full archive.

Continue reading