Using the Apple remote in Ruby

Apple infrared remote controlAfter playing with iremoted and Ruby’s IO.popen I guess I am convinced that Ruby really works as a glue on many levels.

So, using iremoted and capture Apple remote commands in the terminal it is trivial to use the remote to control a Ruby application. Of course, calling OS commands isn’t limited to Ruby.

Here is a minimal dungeon game which you control with the apple remote. If you ever manage to find your way out I would be surprised…

IO.popen (“/Applications/iremoted”) { |f|

x = y = 0

puts “You are standing in an open field west of a white house, with a boarded front door…”

while (line = f.gets.chomp)
if line == “Plus released”
y += 1
end

if line == “Minus released”
y -= 1
end

if line == “Previous released”
x -= 1
end

if line == “Next released”
x += 1
end

puts “You are at coordinate #{x}, #{y}.”
end
}

Who will be first to create a terminal based media center application using Ruby? With some more glue from RubyOSA (the Ruby/AppleEvent Bridge) it should’t be that hard.

Related Posts:

  • No Related Posts
  • http://concentrationstudios.com Chris Carter

    This looks awesome, but, every event makes iremoted put two lines, so the puts “you are at coordinates…” should only happen everyother line. You need a matcher or a counter

  • http://www.peterkrantz.com Pete

    You could be right. However, there is an echo in the dungeon…

  • http://www.martinicity.net MikeBlake

    Hi Peter,

    You get the prize for having the most fun with Ruby today. Very cool, thanks.