andymatuschak.org: Square Signals

Slowly winning an epic war against a fiendish army of sine waves.

  • RubyCocoa + Scripting Bridge = :)

    require ‘osx/cocoa’
    include OSX
    require_framework ‘ScriptingBridge’
    iTunes = SBApplication.applicationWithBundleIdentifier:
    	‘com.apple.iTunes’
    iTunes.playpause
    puts "Now playing: #{iTunes.currentTrack.name}"
    (3)

RubyCocoa + IRB for Testing!

Sometimes, I find myself wondering how a Cocoa method will behave if I do a certain thing. Can I pass nil for this argument? What keys does this return?

Often, I’ll build little test apps to solve these kinds of problems. That requires make a new Xcode project, which has its own directory, then, in many cases, adding some kind of class to instantiate in IB, then calling some methods when applicationDidFinishLaunching:.

Way too much work.

Now, next time I’m wondering which formats NSImage supports, I can just open up IRB in the Terminal and type things like:

require 'osx/cocoa'
OSX::NSImage.imageFileTypes

Well, that was my first try, anyway. That just spits out:

#<OSX::NSCFArray:0x2e09dc class='NSCFArray' id=0x1a73040>

Now, if we passed this NSArray to any Ruby method requiring a Ruby array, it’d be converted automatically:

OSX::NSImage.imageFileTypes.collect { |type| type.reverse }

But if we want to just convert it, we can use the handy to_ruby method:

>> OSX::NSImage.imageFileTypes.to_ruby
=> ["'PDF '", "PDF", "pdf", "'PICT'", "PIC", "pic", "PCT", "pct",
"PICT", "pict", "'EPSF'", "PS", "ps", "EPSI", "epsi", "EPSF", "epsf",
"EPI", "epi", "EPS", "eps", "XBM", "xbm", "HDR", "hdr", "EXR", "exr",
"CR2", "cr2", "DCR", "dcr", "DNG", "dng", "SRF", "srf", "NEF", "nef",
"CRW", "crw", "RAF", "raf", "ORF", "orf", "MRW", "mrw", "ICNS",
"icns", "'jp2 '", "JP2", "jp2", "'qtif'", "QTI", "qti", "QTIF",
"qtif", "'TPIC'", "TGA", "tga", "TARGA", "targa", "'.SGI'", "RGB",
"rgb", "SGI", "sgi", "'8BPS'", "PSD", "psd", "'PNTG'", "MAC", "mac",
"PNT", "pnt", "PNTG", "pntg", "'FPix'", "FPIX", "fpix", "FPX", "fpx",
"'PNGf'", "PNG", "png", "'GIFf'", "GIF", "gif", "'JPEG'", "JPG", "jpg",
"JPEG", "jpeg", "CUR", "cur", "'ICO '", "ICO", "ico", "'BMPf'", "BMP",
"bmp", "'TIFF'", "FAX", "fax", "TIF", "tif", "TIFF", "tiff"]

This technique is really useful for spiking things out without having to make a whole new project.

  • Panic’s released CandyBar 3 with some absolutely gorgeous web design. Check it out for some great UI, both in and out of the app.

    As a side note, it seems to use some kind of in-house update mechanism that isn’t Sparkle.

    (1)

RubyCocoa Shininess in Leopard

Wow, maybe Apple agrees with my sentiments after all. Check out /Developer/Examples/Ruby/RubyCocoa— there’s 40 examples there! Many of the classic examples have been recreated in Ruby, including Stickies and DotView. There are RubyCocoa examples for KVC, KVO, OpenGL, Address Book, Core Data, Core Image, ImageKit, QTKit, PDFKit, and Spotlight.

In other RubyCocoa news, Apple has opened up a new area on Ruby integration at MacOS Forge. Make sure you check out what’s new in Leopard. Interesting tidbits:

  • Most of RubyCocoa was rewritten by Apple. This explains why it’s a lot more solid.
  • Xcode has better Ruby auto-completion, driven by BridgeSupport, a new technology.
  • Interface Builder works correctly with Ruby for outlets and actions.
  • Scripting Bridge works in RubyCocoa.
  • Ruby has DTrace probes, so it works with Instruments!

There’s also now the Ruby and Python Programming Topics in the reference library, including a nice tutorial for RubyCocoa.

These are huge steps forward. My only real wants now are a graphical debugger (I’ll write the bridge to rdb myself, Apple, just open up the interface!) and integrated documentation. I have high hopes.

If you're looking for something specific then give the search form below a try:

RSS Wordpress Grady (theme) Return to the Top ↑