hoodwink.d enhanced
 

juretta.com

RubyOSA - Ruby/AppleEvent Bridge | December 03, 2006-->

December 03, 2006

Get 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 

Diggman

Related Entries


1
Laurent Sansonetti says:
Avatar Sat Jan 06 22:03:02 +0100 2007 | #

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

2
Stefan says:
Avatar Sun Jan 07 09:33:07 +0100 2007 | #

@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.

About

juretta.com is the personal workspace of Stefan Saasen. You can send him an email or read more about this site in the „About“ section.

« Previous entry

Using Spamassassin with Rails ActionM...
posted about 1 year ago

» Next entry

Rspec Rails plugin
posted about 1 year ago

Related Entries

Recent comment

On: “Attachr.com: OpenID support added

You need to kill this spam stuff!

posted about 1 year ago by entropie

Look!

Latest links  RSS  

More...