4. Notes
GUI interaction
When using scripting addition commands that require GUI access (e.g. display_dialog) targeted at the command-line Ruby interpreter, the osax module will automatically convert the non-GUI interpreter process into a full GUI process to allow these commands to operate correctly. If you want to avoid this, target these commands at a faceless GUI application such as System Events instead:
sa = OSAX.osax("StandardAdditions", "System Events")
sa.activate # give focus to System Events
p sa.display_dialog("Ruby says hello!",
:buttons=>["Hi!", "Howdy!", "Duuuude!"],
:default_button=>3)
# Result: {:button_returned=>"Duuuude!"}
64-bit limitations
The OSAX module currently only supports dynamic retrieval of scripting addition terminology when running in 32-bit processes. To use it in 64-bit processes, use the Terminology module's dump method to export a static terminology 'glue' module for the desired scripting addition (running it in a 32-bit process), then import that module and pass it as the second argument to the ScriptingAddition class's initialiser. For example, to export a glue module for Standard Additions:
require 'appscript'
Terminology.dump('/System/Library/ScriptingAdditions/StandardAdditions.osax',
'StandardAdditions', 'standard_additions.rb')
To create a new ScriptingAddition instance using the terminology provided by this glue module:
require 'osax'
require 'standard_additions'
sa = OSAX::ScriptingAddition.new('StandardAdditions', StandardAdditions)
Known problems
When using the OSAX module within RubyCocoa-based applications, avoid creating ScriptingAddition instances before the main event loop is started as this can result in the application behaving strangely (minimised windows don't expand correctly) due to a bug in OS X's OSAGetAppTerminology function.
