Does Ruby offer an Apple event response engine on OS X?

I am 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 will determine the AppleScript command dictionary to which it will respond (the corresponding Apple Events sent to the application), and users / other applications can use the Ruby-Tk application using AppleScript commands. Other scripting languages ​​support this 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 was looking for similar functionality in Ruby and came up empty.

One possible mechanism is the rubyobjc bridge, which provides a low-level interface between Ruby and Objective-C, but this stone seems to be little used and is very lacking in examples and documentation, so I'm not sure it will be a fruitful way.

NB: MacRuby may work, but it is not compatible with Tk, so this excludes MacRuby. Also, RubyOSA and rb-appscript are not what I'm looking for - they allow Ruby to send Apple Events to other applications, rather than receive them.

+7
source share
2 answers

In the absence of other alternatives, it seems to me that I will have to write my own Ruby wrapper for the parts of the AppleEvent C API that I need: mainly AEInstallEventHandler and related functions. Fortunately, Apple still supports this API, although it has been categorized as "legacy" in Apple's developer docs (although, interestingly, it's not out of date). I either integrate these functions using Ruby ffi gem, or most likely using the Ruby C API (which I still need to insert); using the C API directly will reduce the need for dependencies on other gems / modules. If all goes well, I will release it as a gem.

Regarding Donal Fellows comments, my need for custom AppleEvents - those supported through Tk in the documents he recommends can be accessed through Tk calls from the Ruby Tk interface.

+1
source

You might want to check out the appscript library (note: it seems to work only with OS X provided by Ruby), or try using MacRuby , which covers almost all the APIs available in OS X, even with C.

+1
source

All Articles