Projects

Ticket #24 (closed defect: fixed)

Opened 4 years ago

Last modified 4 years ago

ScriptingBridge doesn't get along with NSPredicate (follow up to #22)

Reported by: jordan.breeding@… Owned by: lsansonetti@…
Priority: blocker Milestone: MacRuby 0.1
Component: MacRuby Keywords:
Cc:

Description

Hmm...

So now that #22 some of the code I use on a regular basis to do things with iTunes is failing in a new way. Now the NSPredicate gets created but using it causes problems:

49 jordan@thetourist ~/Desktop/Other/scripts/shootout > /usr/local/bin/irb
irb(main):001:0> framework("Cocoa")
=> true
irb(main):002:0> framework("ScriptingBridge")
=> true
irb(main):003:0> itunes = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes")
=> #<ITunesApplication:0x1453b40>
irb(main):004:0> tracks = itunes.sources.objectWithName("Library").userPlaylists.objectWithName("Music").fileTracks
=> #<SBElementArray:0x14255f0>
irb(main):005:0> notPdf = NSPredicate.predicateWithFormat("not (%K == %@)", "kind", "PDF document")
=> #<NSCompoundPredicate:0x12c4200>
irb(main):006:0> trackArray = trackArray.filteredArrayUsingPredicate(notPdf)
NoMethodError: undefined method `filteredArrayUsingPredicate' for nil:NilClass
	from (irb):6
	from /usr/local/lib/ruby/1.9.0/irb.rb:149:in `block (2 levels) in eval_input'
	from /usr/local/lib/ruby/1.9.0/irb.rb:262:in `signal_status'
	from /usr/local/lib/ruby/1.9.0/irb.rb:146:in `block in eval_input'
	from /usr/local/lib/ruby/1.9.0/irb.rb:145:in `eval_input'
	from /usr/local/lib/ruby/1.9.0/irb.rb:69:in `block in start'
	from /usr/local/lib/ruby/1.9.0/irb.rb:68:in `catch'
	from /usr/local/lib/ruby/1.9.0/irb.rb:68:in `start'
	from /usr/local/bin/irb:12:in `<main>'
irb(main):007:0> tracks = tracks.filteredArrayUsingPredicate(notPdf)
=> #<SBElementArray:0x125cf80>
irb(main):008:0> tracks.arrayByApplyingSelector("album")
RuntimeError: NSGenericException: Apple event returned an error.  Event = 'core'\'getd'{ '----':'obj '{ 'want':'prop', 'from':'obj '{ 'want':'cFlT', 'from':'obj '{ 'want':'cFlT', 'from':'obj '{ 'want':'cUsP', 'from':'obj '{ 'want':'cSrc', 'from':'null'(), 'form':'name', 'seld':'utxt'("Library") }, 'form':'name', 'seld':'utxt'("Music") }, 'form':'test', 'seld':'logi'{ 'logc':'NOT ', 'term':[ 'cmpd'{ 'relo':'=   ', 'obj1':'obj '{ 'want':'prop', 'from':'exmn'($$), 'form':'prop', 'seld':0x00000000 }, 'obj2':'utxt'("PDF document") } ] } }, 'form':'indx', 'seld':'abso'($206C6C61$) }, 'form':'prop', 'seld':'pAlb' } }
Error info = {
    ErrorNumber = -1728;
}
	from (irb):8:in `arrayByApplyingSelector:'
	from (irb):8
	from /usr/local/lib/ruby/1.9.0/irb.rb:149:in `block (2 levels) in eval_input'
	from /usr/local/lib/ruby/1.9.0/irb.rb:262:in `signal_status'
	from /usr/local/lib/ruby/1.9.0/irb.rb:146:in `block in eval_input'
	from /usr/local/lib/ruby/1.9.0/irb.rb:145:in `eval_input'
	from /usr/local/lib/ruby/1.9.0/irb.rb:69:in `block in start'
	from /usr/local/lib/ruby/1.9.0/irb.rb:68:in `catch'
	from /usr/local/lib/ruby/1.9.0/irb.rb:68:in `start'
	from /usr/local/bin/irb:12:in `<main>'
irb(main):009:0>

The first failure is just from me typing in the wrong variable name, but the second one is the NSPredicate in conjunction with ScriptingBridge failing. This does work with Obj-C and RubyCocoa.

Change History

Changed 4 years ago by lsansonetti@…

I investigated a little bit this problem, it seems that it's because of our NSMutableString subclass that doesn't work well as a dictionary key. Hopefully this will be fixed once String is actually a real CFString.

(So, 'kind' is not found in the SB apple event dictionary.)

In the meantime I verified that passing "not (kind == %@)", 'PDF document'" as the predicate format works as expected.

Changed 4 years ago by lsansonetti@…

The problem is because of our NSMutableString special subclass, which doesn't work as a dictionary key.

Once String will be completely re-implemented on top of CFStringRef, this problem will disappear.

Changed 4 years ago by lsansonetti@…

  • status changed from new to closed
  • resolution set to fixed

A temporary fix has been committed as r75/trunk.

Changed 4 years ago by lsansonetti@…

  • milestone changed from MacRuby 1.0 to MacRuby 0.1
Note: See TracTickets for help on using tickets.