Ruby Can';t重写ITunes.h脚本桥中的ITunesTrack或任何其他类

Ruby Can';t重写ITunes.h脚本桥中的ITunesTrack或任何其他类,ruby,itunes,macruby,Ruby,Itunes,Macruby,我正在尝试用MacRuby更新我的iTunes“添加日期”setter 我创建了ScriptingBridge文件,可以从库中读取曲目。由于dateAdded setter是R/O,我需要重写ITunesTrack中的setter,但是,只需重新打开ITunesTrack类,我就得到了这个错误 11:15:09.964 macruby[4888:903] -[ITunesTrack initWithContext:specifier:]: unrecognized selector sent t

我正在尝试用MacRuby更新我的iTunes“添加日期”setter

我创建了ScriptingBridge文件,可以从库中读取曲目。由于dateAdded setter是R/O,我需要重写ITunesTrack中的setter,但是,只需重新打开ITunesTrack类,我就得到了这个错误

11:15:09.964 macruby[4888:903] -[ITunesTrack initWithContext:specifier:]: unrecognized selector sent to instance 0x2006b8ca0
uncaught Objective-C/C++ exception...
2012-05-21 11:15:09.965 macruby[4888:903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ITunesTrack initWithContext:specifier:]: unrecognized selector sent to instance 0x2006b8ca0'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x00007fff8280b784 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x00007fff87d20f03 objc_exception_throw + 45
    2   CoreFoundation                      0x00007fff82865110 +[NSObject(NSObject) doesNotRecognizeSelector:] + 0
    3   CoreFoundation                      0x00007fff827dd8ef ___forwarding___ + 751
    4   CoreFoundation                      0x00007fff827d9a38 _CF_forwarding_prep_0 + 232
    5   ScriptingBridge                     0x00007fff89afcb3d -[SBObject childWithClass:code:keyForm:keyDesc:] + 143
    6   CoreFoundation                      0x00007fff827b6534 -[NSArray getObjects:range:] + 132
    7   CoreFoundation                      0x00007fff828158fe -[NSArray countByEnumeratingWithState:objects:count:] + 206
    8   libmacruby.dylib                    0x000000010016a128 rb_ary_freeze + 10680
    9   libmacruby.dylib                    0x000000010013e018 rb_vm_dispatch + 8504
    10  libmacruby.dylib                    0x00000001000f3a0f rb_objc_block_call + 191
    11  libmacruby.dylib                    0x0000000100028601 rb_Complex + 5473
    12  libmacruby.dylib                    0x000000010013e161 rb_vm_dispatch + 8833
    13  ???                                 0x0000000103200c84 0x0 + 4347399300
    14  ???                                 0x0000000103200531 0x0 + 4347397425
    15  libmacruby.dylib                    0x0000000100154233 rb_vm_run + 531
    16  libmacruby.dylib                    0x0000000100030ca0 ruby_run_node + 80
    17  macruby                             0x0000000100000cf8 main + 152
    18  macruby                             0x0000000100000c54 start + 52
)
terminate called after throwing an instance of 'NSException'
Abort trap
这是我的代码:

#!/usr/local/bin/macruby

    framework 'cocoa'
    framework 'Foundation'
    framework "ScriptingBridge"

    iTunes = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes")
    load_bridge_support_file 'iTunes.bridgesupport'

    old_date = Time.mktime(2001, 01, 01)
    sources = iTunes
      .sources
      .find {|s| 
        s.name == "Library"
      }.playlists
      .find{|p|
        p.name == "Library"
      }.tracks
      .find{|t|
          # dateAdded is of Time class

          if (t.artist.eql?("Bon Iver"))
            t.dateAdded = old_date
            puts "Update #{t.artist} - #{t.album} - #{t.name} "
          end
      } 

    class ITunesTrack
      #def method_missing(m, *args, &block)
      #  puts "Ahoy there!s"
      #  segments = m.to_s.split('_')
      #  missing_meth = segments.map{|part| part.capitalize}.join
      #end

    end

不管我是否注释掉缺少的方法,不管我在类块中放了什么,我都会得到相同的错误。有什么想法吗?

我在macirb中使用了你的代码,它没有任何错误,这很奇怪。我重新安装了XCode和MacRuby,但仍然收到相同的错误。