I am experimenting with Scripting Bridge for the first time, but have SBElementArray into SBElementArray filtering problem according to NSPredicate, which contains the enumeration constant FourCharCode as a criterion.
I wrote a trivial program to identify the source of the library in the iTunes user library using -filteredArrayUsingPredicate: to filter SBElementArray all iTunes sources. I expected to return SBElementArray , which, when computed, will create an array of one element, namely the source of the library. Instead, when I call -get on the returned SBElementArray , I return an empty array.
Surprisingly, if you change the order and instead call -get in SBElementArray all sources to get a specific NSArray , and call -filteredArrayUsingPredicate: in this array with the same predicate as before, I get the desired result. I don't think this is supposed to be necessary, however, and I had a successful SBElementArray filtering using other NSPredicates (e.g. @"name=='Library'" works fine).
The following is a snippet of code. iTunesESrcLibrary is a iTunesESrcLibrary constant defined in the header file created by Scripting Bridge. ( iTunesESrcLibrary = 'kLib' ). I am running 10.6.5.
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);
The output I get is the following:
Attempt 1: <SBElementArray @0x3091010: ITunesSource whose 'cmpd'{ 'relo':'= ', 'obj1':'obj '{ 'want':'prop', 'from':'exmn'($$), 'form':'prop', 'seld':'pKnd' }, 'obj2':1800169826 } of application "iTunes" (88827)> Attempt 1 (evaluated): ( ) Attempt 2: ( "<ITunesSource @0x3091f10: ITunesSource id 65 of application \"iTunes\" (88827)>" )