I'm trying to figure out how to respond to a growl notification in ruby on my Mac running 10.6.8.
Here's the basic code I have written using guard.
require 'growl'
require "pathname"
guard 'shell' do
watch(/(.*)/) do |m|
puts "----------"
path = Pathname.new(m[0])
puts "Pathname = #{path}"
notification = Growl.new
notification.appIcon = "Finder"
if path.exist?
notification.message = "File updated: #{path}"
else
notification.message = "File deleted: #{path}"
end
notification.run
end
end
I want to make it so that when the user clicks on the growl notification, it will trigger a ruby callback (like append a timestamp to the filename).
All of the tutorials I've found on the growl site are for direct Cocoa programming. If I can't figure out how to do this in Ruby, I guess I'll roll up my sleeves and do that, but it seems like it should be easy to do in Ruby.
I'm eventually going to want this to run on Linux and Windows too, which is why I've been shying away from just writing this in Objective-C or AppleScript.
I want to do something like this http://lostechies.com/derickbailey/2011/01/23/responding-to-growl-notification-clicks-and-timeouts-with-macruby/ except in plain ruby instead of macruby.
I don't think the growl
gem is capable of this. The Growl website links to another gem called groem that you might want to check out. It seems to have full support for callbacks.