17 Mar 2010, 18:07
Generic-user-small

Todd Burch (3 posts)

Hi. I’m working page 18 – the speaking-statusbar.rb script.

Everything was working fine until I added the SpeechController.alloc.init.add_menu_to method.

Here’s my code:
#!/usr/bin/env ruby require 'osx/cocoa' include OSX class App < NSObject def applicationDidFinishLaunching(aNotification) statusbar = NSStatusBar.systemStatusBar status_item = statusbar.statusItemWithLength(NSVariableStatusItemLength) image = NSImage.alloc.initWithContentsOfFile("stretch.tiff") raise "Icon file (stretch.tiff) is missing" unless image status_item.setImage(image) SpeechController.alloc.init.add_menu_to(status_item) end end class SpeechController < NSObject def init super_init @synthesizer = NSSpeechSynthesizer.alloc.init return self end end NSApplication.sharedApplication NSApp.setDelegate(App.alloc.init) NSApp.run

And here’s the output I get, also showing my ruby load path and RubyCocoa version.

~/Documents/myruby toddburch $ ruby statusbar-item.rb 2010-03-17 12:48:56.227 ruby[27434:10b] App#applicationDidFinishLaunching: OSX::OCMessageSendException: Can't get Objective-C method signature for selector 'add:menu:to:' of receiver #<SpeechController:0x228eae class='SpeechController' id=0x53ca60> /System/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_wrapper.rb:50:in `ocm_send' /System/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_wrapper.rb:50:in `method_missing' statusbar-item.rb:13:in `applicationDidFinishLaunching' /System/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_wrapper.rb:50:in `ocm_send' /System/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_wrapper.rb:50:in `method_missing' statusbar-item.rb:28 2010-03-17 12:48:56.229 ruby[27434:10b] Can't get Objective-C method signature for selector 'add:menu:to:' of receiver #<SpeechController:0x228eae class='SpeechController' id=0x53ca60> ^C/System/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_wrapper.rb:55:in `ocm_send': Interrupt from /System/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_wrapper.rb:50:in `method_missing' from statusbar-item.rb:28 ~/Documents/myruby toddburch $ /usr/bin/which ruby /usr/bin/ruby ~/Documents/myruby toddburch $ irb >> require 'osx/cocoa' => true >> OSX::RUBYCOCOA_VERSION => "0.13.1" >> quit ~/Documents/myruby toddburch $

Any ideas? Thanks, Todd

17 Mar 2010, 18:09
Generic-user-small

Todd Burch (3 posts)

Well, that’s doesn’t look too nice. Let me try that again.

Code:

 
#!/usr/bin/env ruby 

require 'osx/cocoa'
include OSX 

class App < NSObject 
    def applicationDidFinishLaunching(aNotification) 
        statusbar = NSStatusBar.systemStatusBar 
        status_item = statusbar.statusItemWithLength(NSVariableStatusItemLength) 
        image = NSImage.alloc.initWithContentsOfFile("stretch.tiff") 
        raise "Icon file (stretch.tiff) is missing" unless image 
        status_item.setImage(image) 
        SpeechController.alloc.init.add_menu_to(status_item)
    end

end

class SpeechController < NSObject 
    def init
        super_init 
        @synthesizer = NSSpeechSynthesizer.alloc.init
        return self
    end 
end 

NSApplication.sharedApplication 
NSApp.setDelegate(App.alloc.init) 
NSApp.run

and here’s my output:


~/Documents/myruby toddburch $ ruby statusbar-item.rb
2010-03-17 12:48:56.227 ruby[27434:10b] App#applicationDidFinishLaunching: OSX::OCMessageSendException: Can't get Objective-C method signature for selector 'add:menu:to:' of receiver #<SpeechController:0x228eae class='SpeechController' id=0x53ca60>
    /System/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_wrapper.rb:50:in `ocm_send'
    /System/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_wrapper.rb:50:in `method_missing'
    statusbar-item.rb:13:in `applicationDidFinishLaunching'
    /System/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_wrapper.rb:50:in `ocm_send'
    /System/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_wrapper.rb:50:in `method_missing'
    statusbar-item.rb:28
2010-03-17 12:48:56.229 ruby[27434:10b] Can't get Objective-C method signature for selector 'add:menu:to:' of receiver #<SpeechController:0x228eae class='SpeechController' id=0x53ca60>
^C/System/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_wrapper.rb:55:in `ocm_send': Interrupt
    from /System/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_wrapper.rb:50:in `method_missing'
    from statusbar-item.rb:28

~/Documents/myruby toddburch $ /usr/bin/which ruby 
/usr/bin/ruby
~/Documents/myruby toddburch $ irb
>> require 'osx/cocoa'
=> true
>> OSX::RUBYCOCOA_VERSION
=> "0.13.1" 
>> quit
~/Documents/myruby toddburch $ 

18 Mar 2010, 05:05
Generic-user-small

Todd Burch (3 posts)

Nevermind. I turned the page and there it was. duh.

  You must be logged in to comment