My problem was that I needed to hide the iTunes window (the same as using the ⌘H shortcut) so that the Ruby application didn't lose focus. Unfortunately it took me a long time to find out how to do it.
I didn't need to deal with OSAX. Here's a snippet of code that demonstrates the necessary incantation:
require 'rubygems' require 'appscript' itunes = Appscript.app('iTunes') itunes.activate() itunes.stop # Hide the iTunes window Appscript.app('System Events').processes['iTunes'].visible.set(false)Here is what the actual AppleScript (which I was able to find easily) looks like:
tell application "System Events" set visible of process "iTunes" to false end tellYou can see how the 'Rubyised' version maps to it, although it took a lot of Googling to translate!