Question

I'm working on a desktop application for OS X using Ruby-Tk, and I would like to provide an Apple Events interface for the application. This means that the application would define a dictionary of AppleScript commands that it would respond to (corresponding to Apple Events being sent to the application), and users/other applications could script the Ruby-Tk application with AppleScript commands. Other scripting languages support such functionality--Python through the py-aemreceive library at http://appscript.svn.sourceforge.net/viewvc/appscript/py-aemreceive/ and Tcl through the tclAE library at http://tclae.sourceforge.net/. I've been looking for similar functionality in Ruby and have come up empty.

One possible mechanism is the rubyobjc bridge, which provides a low-level interface between Ruby and Objective-C, but this gem appears to be little-used and is sorely lacking in examples and documentation, so I am not sure if this would be a fruitful path to pursue.

NB: MacRuby might work but it is not compatible with Tk, so that rules out MacRuby. Also, RubyOSA and rb-appscript are not what I am looking for--they allow Ruby to send Apple Events to other applications, not receive them.

Was it helpful?

Solution

In the absence of other alternatives, it appears I am going to have to write my own Ruby wrapper for the portions of the AppleEvent C API that I need: mainly AEInstallEventHandler and related functions. Fortunately Apple still supports this API even though it has been relegated to "legacy" status in Apple's developer docs (though, interestingly, it is not deprecated). I'll either integrate these functions via Ruby's ffi gem or, more likely, via Ruby's C API (which I still have to dig into); using the C API directly would reduce the need for dependencies on other gems/modules. If this goes well I will release it as a gem.

Regarding Donal Fellows' comment, my need is for custom AppleEvents--the ones supported via Tk in the docs he recommends can likely be accessed through calls to Tk from Ruby's Tk interface.

OTHER TIPS

You might want to check the appscript library (note: Seems to only work with the OS X-provided Ruby), or try using MacRuby, which wraps pretty much everything of the APIs available in OS X, even the C ones.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top