Skip to content

Instantly share code, notes, and snippets.

@techbelly
Created April 15, 2009 02:14
Show Gist options
  • Save techbelly/95556 to your computer and use it in GitHub Desktop.
Save techbelly/95556 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "rubygems"
require "opencv"
include OpenCV
class IChat
def available!
tell_me_to "set status to available"
end
def away!
tell_me_to "set status to away"
end
def tell_me_to(message)
lines = ['tell application "System Events"',
'if exists process "iChat" then',
'tell application "iChat"',
message,
'end tell',
'end if',
'end tell']
cmd = "-e '#{lines.join("' -e '")}'"
system "osascript #{cmd}"
end
end
camera = CvCapture.open
face_detector = CvHaarClassifierCascade::load("haarcascade_frontalface_alt.xml")
ichat = IChat.new
check_every = 10
while true
image = camera.query
faces = face_detector.detect_objects(image)
if faces.empty?
ichat.away!
else
ichat.available!
end
sleep(check_every)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment