Created
June 12, 2011 05:41
-
-
Save youpy/1021283 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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