Ship It! LIVEShip It! LIVE
home about services writing contact

We develop, test, and create fine software products, and design creative solutions to your problems.
The development of software is an intrinsically creative process. We are dedicated to improving our mastery of the art.
Links · RSS Feed
Popular Pages

That's got to be one of the *best* choice of title since the Mythical Man Month!!
-Kenneth Sizer
It's rare to have this much fun reading a book about software. The ideas are smart, relevant, and fundamental. I can be a better programmer today because of the things I read today.
-Joe Fair
Quoting Watts Humphrey, "Developers are caught in a victim's mentality." We never think it's our fault, it's always somebody else's.
-Jared Richardson

Scripting OS X Applications with Ruby (Nov 20)

I needed to pull some statistics and information out of TextMate but they don't have a formal API. Then a co-worker spotted this project

http://blog.ardes.com/2007/9/14/os-x-textmate-user-free-time-tracker-matewatch

which has an example of the RubyOSA bridge that exposes the Apple events that an application makes available. That is to say, I can get access to tons of applications (including iTunes and TextMate) from a Ruby app.

RubyOSA is easy to use. Here's a quick example that shows the list of your TextMate documents.

require 'rubygems'
require 'rbosa'
tm = OSA.app("Textmate")
tm.documents.each{|doc|
 puts doc.name
}

Another scriptable application is iTunes. You can just as easily type

iTunes = OSA.app('iTunes')
iTunes.pause
iTunes.play

But the question you'll immediately have is what methods are availabe for iTunes or TextMate? For that you'll see the bundled rdoc-osa.

rdoc-osa will generate an HTML document (rdoc style) of the interfaces for any particular application. To create the TextMate documentation, just type:

rdoc-osa  --name TextMate

Then look in the doc folder for your index.html.

Also, be sure you install the RubyOSA gem first.

 sudo gem install rubyosa

For more information, see RubyOSA on Rubyforge or this page on the Apple Developer site.

Update: Thanks to reader Botond Orban for pointing out that the documentation command is rdoc-osa, not doc-osa. I'm not sure what I was thinking when I typed that! -jrr

Category: Ruby

RubyRX/AgileRX (2009-08-30)
The RubyRX and AgileRX conferences are colocating in Philly
RubyRX/AgileRX (2009-09-04)
The RubyRX and AgileRX conferences are colocating in DC


© 2007 Agile Artisans.