Skip to content

Instantly share code, notes, and snippets.

@no6v
Forked from ohac/recvgrowl.rb
Created November 23, 2009 06:33
Show Gist options
  • Save no6v/240930 to your computer and use it in GitHub Desktop.
Save no6v/240930 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'rubygems'
require 'ruby-growl'
require 'socket'
require 'shellwords'
require 'cgi'
UDPSocket.open do |u|
u.bind('localhost', Growl::GROWL_UDP_PORT)
loop do
packet = u.readpartial(1500)
digest = packet.slice!(-16, 16)
next if digest != Digest::MD5.digest(packet)
version, type, flags, *sizes = packet.unpack(Growl::GNN_FORMAT)
next if version != Growl::GROWL_PROTOCOL_VERSION
next if type != Growl::GROWL_TYPE_NOTIFICATION
data = sizes.pop
name, title, desciption, app_name = sizes.map do |size|
data.slice!(0, size)
end
system Shellwords.join(['notify-send', title, CGI.escapeHTML(desciption)])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment