RubyOSA - Ruby/AppleEvent Bridge | December 03, 2006-->
December 03, 2006Get http://rubyosa.rubyforge.org/ if you are programming Ruby on Mac OS X!
RubyOSA is a bridge that connects Ruby to the Apple Event Manager infrastructure. In other words, it allows you to do in Ruby whatever you could do in AppleScript.
To install rubyosa just install it via Ruby gems (which is obviously only useful if you are on a mac).
macbook:~ stefan$ sudo gem install rubyosa [...] Successfully installed rubyosa-0.2.0
The following example shows how to print all the contacts your Address Book contains.
RubyOsa seems to work better with Ruby 1.8.4 than with Ruby 1.8.5.
This has been fixed
# sudo gem install rubyosa require 'rubygems' require 'rbosa' # rdoc-osa --name "Address Book" def print_person(pe) puts pe.name puts "\tE-Mail: " + pe.emails.map{|email| email.value}.join(", ") \ unless pe.emails.size < 1 puts "\tAddresses: " + pe.addresses.map{|a| a.formatted_address}\ .join(", ") unless pe.addresses.size < 1 end ab = OSA.app('Address Book') ab.people.each do |pe| print_person pe end

Laurent Sansonetti says: http://chopine.be/lrz
Hi Stefan,
Nice article! Would you mind if we re-use your address book code as an official RubyOSA sample code?
Also, could you elaborate when you say that RubyOSA works better with Ruby 1.8.4 than 1.8.5?
Thanks in advance,
Laurent
Stefan says: http://www.juretta.com
@Laurent:
You are certainly welcome to use the code!
I’m getting random “Segmentation fault” errors when running the example code using Ruby 1.8.5 while the example works fine with Ruby 1.8.4.