10/21/07
Fun with Ruby and OS X
Today I decided to start teaching my 6 year old Ruby. The easiest thing I could think of off hand was to "make the computer count" to any number she wanted :). Of course it wasn't enough to see it count, she wanted to hear it count!
There were only a few ways I knew to do this; find a ruby sound library; or easier, use AppleScript. I choose AppleScript just to show her how it could speak. But all along wishing I had gone the ruby route to keep it pure.
Thus enters my find of the day, rb-appscript.
To install it just:
Now run this nice little script and you'll have your computer counting to 100 out loud in no time!
Of course you could modify this to be slimmer in code and say anything. I just wanted to make it clear and readable to everyone. I actually modified this to sort through my address book, count the number of people it found, and then start reading through the list. It made me feel like I have more friends than I actually have (ah the bliss)!
Hope you guys have fun with this :).
There were only a few ways I knew to do this; find a ruby sound library; or easier, use AppleScript. I choose AppleScript just to show her how it could speak. But all along wishing I had gone the ruby route to keep it pure.
Thus enters my find of the day, rb-appscript.
To install it just:
sudo gem install rb-appscriptNow run this nice little script and you'll have your computer counting to 100 out loud in no time!
require "rubygems"
require "appscript"
require "osax"
include Appscript
count = 100
speaker = OSAX::ScriptingAddition.new("StandardAdditions")
speaker.say("I am now going to count to, #{count}", :using => "Victoria")
count.times do |current_number|
current_number = current_number + 1
puts current_number
speaker.say(current_number, :using => "Victoria")
end
speaker.say("ta da ah!", :using => "Victoria")
Of course you could modify this to be slimmer in code and say anything. I just wanted to make it clear and readable to everyone. I actually modified this to sort through my address book, count the number of people it found, and then start reading through the list. It made me feel like I have more friends than I actually have (ah the bliss)!
Hope you guys have fun with this :).
Labels: osx applescript coding ruby


0 Comments:
Links to this post:
Create a Link
<< Home