Monitoring File Changes and Getting Notified via Growl

February 14, 2010

I’ve been experimenting with Duby for faster computations in Opaz-PlugDK. I wanted to stay in the editor, triggering compilations with opt+s, and to be notified through Growl when something happens (in my case, compiling Duby).

Here’s how to do it, using FSSM and Ruby-Growl.

# all cross-platform gems in theory
require 'fssm'
require 'ruby-growl'

growl = Growl.new "localhost", "ruby-growl",
                  ["Opaz-PlugDK"]

FSSM.monitor('plugins', '**/*.duby') do
  update do |base, relative|
    in_folder(base) do
      growl.notify "Opaz-PlugDK", relative,
                   "Compiling..." 
      unless system("dubyc -java #{relative}")
        growl.notify "Opaz-PlugDK", relative,
                     "Duby compile failed" 
      else
        growl.notify "Opaz-PlugDK", relative,
                     "OK!" 
      end
    end
  end
end

I really love Ruby for those things :)