You might want to have a look at rb-appscript. The python version (by the same author) works great and the author is knows a lot about the arcana of OSA and apple-scripting.