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