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

If your shop has trouble shipping quality software on time -- and let's face it, most do -- then this book is for you. If you're a manager, I'd say that doubly so.
-Ernest Friedman-Hill "JavaRanch Sheriff"
...It would be really nice if, as an industry, we could stop being such a bunch of screwed-up clowns and start living up to our potential. Ship It! is one of the things that could help, if only tho...
-Mike Gunderloy
With much code, all eyes are shallow
-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


© 2007 Agile Artisans.