Here’s a fantastic tutorial from MacZealots to get you started on automating your Mac using Ruby (instead of, say, AppleScript). If AppleScript is too hinky and irregular for you programmer types, this might be just the ticket.
Great RubyOSA tutorial
Written on May 3, 2007