简体   繁体   English

响应单击ruby中的咆哮通知

[英]Responding to a click on a growl notification in ruby

I'm trying to figure out how to respond to a growl notification in ruby on my Mac running 10.6.8. 我试图弄清楚如何在运行10.6.8的Mac上响应ruby中的咆哮通知。

Here's the basic code I have written using guard. 这是我使用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. 如果我不知道如何在Ruby中执行此操作,我想我会袖手旁观并执行此操作,但是似乎在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. 我最终将希望它也可以在Linux和Windows上运行,这就是为什么我一直回避仅使用Objective-C或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. 我想做这样的事情http://lostechies.com/derickbailey/2011/01/23/responding-to-growl-notification-clicks-and-timeouts-with-macruby/,但用纯红宝石代替了macruby。

I don't think the growl gem is capable of this. 我不认为growl宝石能做到这一点。 The Growl website links to another gem called groem that you might want to check out. Growl网站链接到您可能要检出的另一种名为groem的宝石。 It seems to have full support for callbacks . 它似乎完全支持回调

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM