This guide will explain how to use RubyOSA to control scriptable Mac OS X applications. We expect you to have some Ruby programming background and that you have properly installed RubyOSA on your machine.
RubyOSA is a bridge between Ruby and the Open Scripting Architecture (OSA). The key idea is to create a Ruby API on the fly based on a target application’s scriptable definition.
Once you target an application with RubyOSA you get a special kind of proxy object, which is the entry point of the generated Ruby API.
Let’s start with something easy:
require 'rbosa' # (1) app = OSA.app('iTunes') # (2) puts app.current_track.name # (3)
First, we need to require the RubyOSA bridge (1). Note that if you installed
RubyOSA via RubyGems you might want to
require 'rubygems' before.
Next, we get a handle to the iTunes application (2) in the form of an
OSA::ITunes::Application object. The
OSA::ITunes module and everything inside
is automatically generated during
Finally, we use the application object to get the name of the current track and we print the result to the standard output (3).