Skip to content

Instantly share code, notes, and snippets.

@morr
Created November 5, 2011 12:34
Show Gist options
  • Save morr/1341458 to your computer and use it in GitHub Desktop.
Save morr/1341458 to your computer and use it in GitHub Desktop.
Linux libnotify notifier
#!/usr/bin/ruby
require 'rubygems'
require 'libnotify'
require 'getoptlong'
parser = GetoptLong.new
parser.set_options(["-s", "--summary", GetoptLong::REQUIRED_ARGUMENT],
["-b", "--body", GetoptLong::REQUIRED_ARGUMENT],
["-i", "--icon_path", GetoptLong::REQUIRED_ARGUMENT]
);
options = {:summary => "", :body => "", :icon_path => nil}
parser.each do |opt,arg|
case opt
when "-s"
options[:summary] = arg
when "-b"
options[:body] = arg
when "-i"
options[:icon_path] = arg
end
end
n = Libnotify.new do |notify|
notify.summary = options[:summary]
notify.body = options[:body]
notify.timeout = 1 # 1.5 (s), 1000 (ms), "2", nil, false
notify.urgency = :normal # :low, :normal, :critical
notify.icon_path = options[:icon_path] if options[:icon_path]
end
n.show!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment