RubyCocoa

RubyCocoa is a bridge between the Mac OS X Cocoa Framework API that makes it callable from Ruby code. You can create applications, objects, call Mac OS X Services. You can even call Applescript:


require 'osx/cocoa'
include OSX
def speak (str)
str.gsub! (/"/, '\"')
src = %(say "#{str}")
NSAppleScript.alloc.initWithSource(src).executeAndReturnError(nil)
end
speak "Hello World!"
speak "Kon nich Wah. Ogan key desu ka?"

Ben Bleything submitted a talk to RubyConf, titled "Harmonize: Exploiting RubyCocoa and Sync Services for Fun and Profit" where he discusses making a wrapper around the SyncAPI in Ruby. (blog post introducing Harmonize)

RubyCocoa looks like it may have stagnated a little as the last release was November 2005, but perhaps with such a renewed interest in Ruby, and Mac OS X gaining popularity, perhaps new life with be breathed into it. Projects such as SyncBridge and Harmonize also obviously help.

Update: Check out the very good examples and information at RubyCocoa.com, including how to use your Apple Remote from RubyCocoa .

About this article

written on
posted in ProgrammingAppleRubyApplescriptMac OS X Back to Top

About the Author

Andrew Turner is an advocate of open standards and open data. He is actively involved in many organizations developing and supporting open standards, including OpenStreetMap, Open Geospatial Consortium, Open Web Foundation, OSGeo, and the World Wide Web Consortium. He co-founded CrisisCommons, a community of volunteers that, in coordination with government agencies and disaster response groups, build technology tools to help people in need during and after a crisis such as an earthquake, tsunami, tornado, hurricane, flood, or wildfire.