Skip to content

Instantly share code, notes, and snippets.

@youpy
Created June 12, 2011 05:41
Show Gist options
  • Save youpy/1021283 to your computer and use it in GitHub Desktop.
Save youpy/1021283 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra/base'
require 'ruby-growl'
require 'launchy'
class GrowlServer < Sinatra::Base
set :port, 5678
def initialize(app = nil, &block)
super(app, &block)
@name = 'growl server'
@growl = Growl::GNTP.new('localhost', @name, [$0])
@growl.register
end
get '/' do
text = params[:text]
url = params[:url]
if text
notify(text, url)
end
'ok'
end
def notify(text, url)
@growl.notify($0, @name, text, 0, false, nil, nil) do |res|
if url && res['Notification-Callback-Result'] == 'CLICKED'
Launchy.open(url)
end
end
end
run! if app_file == $0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment