开发者

Adding Growl notifications after Rake tasks are finished

开发者 https://www.devze.com 2023-01-12 00:56 出处:网络
Is there a way to add Growl notifications to the end of all Rake tasks? I initially thought of creating a task that Growls, and adding it as a dependency to tasks I want alerts from, but realized the

Is there a way to add Growl notifications to the end of all Rake tasks?

I initially thought of creating a task that Growls, and adding it as a dependency to tasks I want alerts from, but realized the dependencies get run before the task begins. Is there a way to add tasks to be run afte开发者_运维技巧r certain Rake tasks are finished?

It'd be really useful so I don't have to sit there waiting for long tasks.

** update 8/17/2010 **

Here is the solution for doing it with growlnotify...put this in your Rakefile:

def growl(message)
  growlnotify = `which growlnotify`.chomp
  system %(#{growlnotify} -sm #{message})
end

task_names = Rake.application.top_level_tasks
task_names.each do |name|
  Rake.application[name].enhance { growl "'Task #{name} completed (#{Time.now})'" }
end

-- Credit to Alkaline - see his solution for using ruby-growl below --


Here's how you can implicitly invoke a growl action for the calling (top level) tasks

require 'rake'
require 'ruby-growl'

task :task1 do puts "Doing task 1"; sleep 1; end
task :task2 do puts "Doing task 2"; sleep 1; end
task :default => [:task1, :task2]

# Add a growl action to all top level tasks
task_names = Rake.application.top_level_tasks
task_names.each do |name|
  Rake.application[name].enhance {growl(name)}
end

def growl(name)
  g = Growl.new "localhost", "ruby-growl", ["ruby-growl Notification"]
  g.notify "ruby-growl Notification", "My Project", "Task #{name} completed"
end


The gem rakegrowl does this very simply. All you have to do is install the rakegrowl gem and alias rake to rake -rubygems -r rakegrowl in your .bashrc.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号