Skip to content

Instantly share code, notes, and snippets.

@mustardamus
Created June 6, 2010 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mustardamus/427348 to your computer and use it in GitHub Desktop.
Save mustardamus/427348 to your computer and use it in GitHub Desktop.
require "rubygems"
require 'directory_watcher'
commands = [
{ :tell => "Firefox", :to => "activate" },
{ :tell => "System Events", :to => "keystroke \"1\" using command down" },
{ :tell => "System Events", :to => "keystroke \"r\" using command down" },
{ :tell => "TextMate", :to => "activate" }
]
dw = DirectoryWatcher.new ARGV[0]
dw.interval = 1.0
dw.glob = "**/*.*"
dw.add_observer {|*args| args.each {|event|
unless event.type == :added
commands.each do |command|
%x[osascript -e 'tell application "#{command[:tell]}" to #{command[:to]}']
end
end
puts event
}}
trap("SIGINT") do
dw.stop
exit
end
dw.start
while(true) do
sleep 60
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment