Projects
Home     Blog     Install     New Ticket     View Tickets     Browse Source

MacRuby with RubyInject

WARNING - WIP page; Science Fiction ahead!

RubyInject is a Mac OS X framework that allows you to inject the Ruby interpreter into a running application. The existing documentation explains how to do this with RubyCocoa; this page explains how to do the same thing with MacRuby, then explores some further trickery...

Downloading and Installation

Downloading and installation instructions are available, respectively, on the RubyInject web site and README file. However, here is a terse summary of what I saw:

$ sr=https://rubycocoa.svn.sourceforge.net/svnroot
$ svn co $sr/rubycocoa/branches/users/lrz/RubyInject

$ cd RubyInject
$ xcodebuild SYMROOT=/tmp
...
$ cp -r /tmp/Release/RubyInject.framework /Library/Frameworks

$ sudo macgem install dnssd
2008-10-30 20:02:41.908 macruby[25691:a0b] *** +[RFC2253DN module_function]:
  unrecognized selector sent to class 0x9311ad0
Building native extensions.  This could take a while...
ERROR:  Error installing dnssd:
	ERROR: Failed to build gem native extension.

/Library/Frameworks/MacRuby.framework/Versions/0.3/usr/bin/macruby extconf.rb install dnssd
checking for dns_sd.h... yes
checking for unistd.h... yes
checking for sys/types.h... yes
checking for sys/socket.h... yes
checking for sys/param.h... yes
checking for sys/if.h... no
checking for net/if.h... yes
checking for htons()... no
need function htons

Gem files will remain installed in /Library/Frameworks/MacRuby.framework/
  Versions/0.3/usr/lib/ruby/Gems/1.9.0/gems/dnssd-0.7.0 for inspection.
Results logged to /Library/Frameworks/MacRuby.framework/
  Versions/0.3/usr/lib/ruby/Gems/1.9.0/gems/dnssd-0.7.0/ext/gem_make.out

Usage

The supplied inject.rb script is rather RubyCocoa-specific. So, use the modified version (mr_inject.rb) (that will be) attached to this page. Usage should look something like this:

$ open -a textedit
$ ps auxwww | grep TextEdit | grep -v grep
lrz 69194 ...
$ sudo macruby inject.rb 69194
Password:
>> NSApp
=> "#<OSX::NSApplication:0xafd0962 class='NSApplication' id=0x1168e0>"
>> NSApp.windows
=> "#<NSCFArray [#<OSX::NSWindow:0xafc7074 class='NSWindow' id=0x177f10>]>"