RubyOSA - Ruby/AppleEvent Bridge
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