Nick Sieger: RubyConf: Mac OS X and Ruby tag:blog.nicksieger.com,2005:Typo Typo 2007-08-31T18:16:44+00:00 Nick urn:uuid:af12cc45-1478-4019-ab07-a5875de0d70b 2006-11-11T02:56:16+00:00 2007-08-31T18:16:44+00:00 Comment on RubyConf: Mac OS X and Ruby by Nick <p>I don&#8217;t know of any published information about this. You might wish to contact Laurent to see what the timeframe is for this (I suspect we&#8217;d see something in Leopard or one of the updates to it).</p> Anonymous Coward urn:uuid:7026c986-947f-4e02-b1ea-5e7810d254d1 2006-11-11T01:10:36+00:00 2007-08-31T18:16:44+00:00 Comment on RubyConf: Mac OS X and Ruby by Anonymous Coward <p>Where can I find more information on Ruby.framework?</p> cabo urn:uuid:0a4e2c9b-c421-4cee-80e6-fe02ed731d4b 2006-10-24T13:33:38+00:00 2007-08-31T18:16:44+00:00 Comment on RubyConf: Mac OS X and Ruby by cabo <p>Thanks, <em>has</em> &#8211; no wonder I got confused if there are two things that are called RubyOSA. Yes, your comment did help :-)</p> has urn:uuid:6321d379-052e-4e18-9214-0251831af246 2006-10-23T17:40:20+00:00 2007-08-31T18:16:44+00:00 Comment on RubyConf: Mac OS X and Ruby by has <p>Reply to cabo:</p> <p>I&#8217;m not doing any comparisons of rb-appscript and RubyOSA till RubyOSA 0.1 is out and I&#8217;ve had a chance to look at it. But to answer to the rest of your query:</p> <p>RubyOSA and rb-appscript are both just bridges from the existing CRuby interpreter to OS X&#8217;s Apple Event Manager. For attachability you need an OSA language - essentially, a Ruby interpreter wrapped up as a Component Manager component. (Same idea as ActiveScriptRuby, except ASR&#8217;s based on Windows COM, of course.)</p> <p>You can get already a basic OSA component for Ruby, also called RubyOSA (no relation), from:</p> <p><a href='http://homepage.mac.com/philip_aker/osa/osa.html' rel="nofollow">http://homepage.mac.com/philip_aker/osa/osa.html</a></p> <p>This supports the core OSA operations - loading and storing OSA script files (.scpt), compiling from source, and executing - and should be adequate for simple tasks such as attaching alarm scripts to iCal. However, it doesn&#8217;t support the more advanced OSA features such as sending and receiving events -needed for things like Folder Actions and Mail rules - so its usefulness is somewhat limited.</p> <p>FWIW, I wouldn&#8217;t mind writing a full Ruby OSA component myself, but I&#8217;d need some help from a Ruby expert first as I don&#8217;t know anything about CRuby embedding. (Offers welcome.)</p> <p>HTH</p> cabo urn:uuid:7da199e3-c2b0-4d15-8080-6c71532a79c9 2006-10-23T11:20:06+00:00 2007-08-31T18:16:43+00:00 Comment on RubyConf: Mac OS X and Ruby by cabo <p>Question for the hallway: How do RubyOSA and rb-appscript compare? The latter works well today, but does not support &#8220;attachability&#8221;, AFAIU. But where do we go from here?</p> Nick Sieger urn:uuid:13013e7d-b186-4edb-aa5c-4a5fbfc82b4f 2006-10-21T18:58:33+00:00 2007-08-31T16:50:39+00:00 RubyConf: Mac OS X and Ruby <p><a href="http://chopine.be/lrz/diary/">Laurent Sansonetti</a>, who works at Apple Computer, is now in charge of maintaining Ruby inside the OS.</p> <h2>History of Ruby in the OS</h2> <ul> <li>10.2 shipped with Ruby 1.6.7</li> <li>10.3 shipped with Ruby 1.6.8</li> <li>10.4 shipped with 1.8.4, and the latest software update has Ruby fixes to allow compilation of C extensions</li> </ul> <p>Apple is actively looking to improve Ruby support in future versions of the OS in several areas:</p> <ul> <li>Ruby.framework</li> <li>64 bit support</li> <li>Controlling scriptable applications</li> <li>Cocoa development</li> </ul> <h2>Framework</h2> <p>Why a framework? It&#8217;s easier for Mac development. It allows multiple versions, and lets you bundle Ruby inside your application. It&#8217;s also compatible with original layout <code>/usr/bin/ruby</code> =&gt; <code>/System/Library/Frameworks/Ruby.framework/Current/bin/ruby</code></p> <h2>Misc</h2> <ul> <li>Include IRB support, RubyGems, plus important gems: Rake, Rails, libxml2 and sqlite3 bindings, DNSSD (Zeroconf)</li> </ul> <h2>Controlling scriptable applications</h2> <p>Traditionally applications are scripted by AppleScript. Apple Events are the IPC glue between the two.</p> <p>RubyAEOSA is a Ruby wrapper for Apple events, that was started in 2001, but not active since 2003. The code required is unnecesarrily verbose. Instead, you could wrap and execute with AppleScript, but it&#8217;s slower and limited by knowledge of AppleScript.</p> <p>RubyOSA is a new project created by Apple, intended to be a successor to RubyAEOSA, under active development and used today. It has a much more Rubyish API, generating Ruby code on the fly and sending events lazily. Apple events are completely hidden.</p> <div class="typocode"><pre><code class="typocode_ruby "><span class="ident">require</span> <span class="punct">'</span><span class="string">rbosa</span><span class="punct">'</span> <span class="ident">itunes</span> <span class="punct">=</span> <span class="constant">OSA</span><span class="punct">.</span><span class="ident">app</span><span class="punct">('</span><span class="string">itunes</span><span class="punct">')</span> <span class="ident">itunes</span><span class="punct">.</span><span class="ident">current_track</span> <span class="ident">itunes</span><span class="punct">.</span><span class="ident">current_track</span><span class="punct">.</span><span class="ident">name</span> <span class="ident">itunes</span><span class="punct">.</span><span class="ident">current_track</span><span class="punct">.</span><span class="ident">artist</span> <span class="ident">itunes</span><span class="punct">.</span><span class="ident">current_track</span><span class="punct">.</span><span class="ident">size</span> <span class="ident">itunes</span><span class="punct">.</span><span class="ident">play</span> <span class="ident">itunes</span><span class="punct">.</span><span class="ident">pause</span> <span class="ident">itunes</span><span class="punct">.</span><span class="ident">sound_volume</span> <span class="punct">=</span> <span class="number">0</span> <span class="number">100</span><span class="punct">.</span><span class="ident">times</span> <span class="punct">{|</span><span class="ident">i</span><span class="punct">|</span> <span class="ident">itunes</span><span class="punct">.</span><span class="ident">sound_volume</span> <span class="punct">=</span> <span class="ident">i</span><span class="punct">;</span> <span class="ident">sleep</span> <span class="number">0.1</span> <span class="punct">}</span></code></pre></div> <p>0.1.0 release is coming soon, <code>gem install rubyosa</code>.</p> <h2>Cocoa development</h2> <p>Mac development framework, mostly using Objective-C. RubyCocoa is a Ruby/Objective-C bridge, now under active development with support from Apple. It creates Obj-C classes to Ruby proxies and vice-versa. Messages and exceptions are forwarded, and types are converted.</p> <p>It uses a message convention. &#8216;:&#8217; are substituted with &#8216;_&#8217; in the method name (selector). The final &#8216;_&#8217; can be omitted, but can lead to ambiguities. It may be mandatory in a future release.</p> <p>Some challenges remain in the Ruby/Obj-C bridge.</p> <p><em>Problem: Speed of method invocation.</em> Solution: libffi from gcc, allows invocation of arbitrary foreign function interfaces.</p> <p><em>Problem: Maintenance.</em> Currently RubyCocoa needs to be rebuilt to take into consideration new APIs, so to solve, a metadata framework is being built to allow the information to be more dynamic, and a metadata generator tool will help with creating a metadata file for new APIs</p> <p>These latest developments are available from the <code>apple-unstable</code> branch in SVN from rubyforge.</p> <h2>Future</h2> <ul> <li>&#8220;Toll free bridge&#8221; &#8211; implement Ruby primitive types with CoreFoundation objects so that no type conversion is necessary</li> <li>Garbage collection &#8211; Objective-C will be getting garbage collection in the future, and the idea is to implement the Obj-C garbage collector in Ruby through Obj-C APIs.</li> </ul>