Note that there are some explanatory texts on larger screens.

plurals
  1. POScripting Bridge and filtering SBElementArrays using NSPredicate and FourCharCodes
    text
    copied!<p>I'm experimenting with Scripting Bridge for the the first time, but have run into an issue with filtering a <code>SBElementArray</code> according to a NSPredicate containing a FourCharCode enum constant as a criterion.</p> <p>I wrote a trivial program to identify the "library" source in a user's iTunes library, by using <code>-filteredArrayUsingPredicate:</code> to filter the <code>SBElementArray</code> of all iTunes sources. I was expecting to get back an <code>SBElementArray</code> that, when evaluated, would produce an array of one element, namely the library source. Instead, when I call <code>-get</code> on the returned <code>SBElementArray</code>, I get back an empty array.</p> <p>Perplexingly, if change the order and instead call <code>-get</code> on the <code>SBElementArray</code> of all sources to get a concrete <code>NSArray</code>, and call <code>-filteredArrayUsingPredicate:</code> on this array with the same predicate as before, I do get the desired result. I don't believe this is supposed to be necessary however, and I've had success filtering a <code>SBElementArray</code> using other NSPredicates (e.g. <code>@"name=='Library'"</code> works fine).</p> <p>The code snippet is below. <code>iTunesESrcLibrary</code> is a FourCharCode constant defined in the header file generated by Scripting Bridge. (<code>iTunesESrcLibrary = 'kLib'</code>). I'm running 10.6.5.</p> <pre><code>iTunesApplication* iTunes = [[SBApplication alloc] initWithBundleIdentifier:@"com.apple.iTunes"]; NSPredicate* libraryPredicate = [NSPredicate predicateWithFormat:@"kind == %u", iTunesESrcLibrary]; SBElementArray* allSources_Attempt1 = [iTunes sources]; SBElementArray* allLibrarySources_Attempt1 = (SBElementArray*)[allSources_Attempt1 filteredArrayUsingPredicate:libraryPredicate]; NSLog(@"Attempt 1: %@", allLibrarySources_Attempt1); NSLog(@"Attempt 1 (evaluated): %@", [allLibrarySources_Attempt1 get]); NSArray* allSources_Attempt2 = [[iTunes sources] get]; NSArray* allLibrarySources_Attempt2 = [allSources_Attempt2 filteredArrayUsingPredicate:libraryPredicate]; NSLog(@"Attempt 2: %@", allLibrarySources_Attempt2); </code></pre> <p>The output I get is the following:</p> <pre><code>Attempt 1: &lt;SBElementArray @0x3091010: ITunesSource whose 'cmpd'{ 'relo':'= ', 'obj1':'obj '{ 'want':'prop', 'from':'exmn'($$), 'form':'prop', 'seld':'pKnd' }, 'obj2':1800169826 } of application "iTunes" (88827)&gt; Attempt 1 (evaluated): ( ) Attempt 2: ( "&lt;ITunesSource @0x3091f10: ITunesSource id 65 of application \"iTunes\" (88827)&gt;" ) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload