Eric Lee wrote:

I have a problem getting the iTunes list, and then making the
tableview display the iTunes list.


Using objc-appscript [1], here's how to list the name, artist and album of every track in the current playlist:


#import "ITGlue/ITGlue.h"

// To create glue files: osaglue  -o ITGlue  -p IT  iTunes

int main (int argc, const char * argv[]) {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        
ITApplication *itunes = [ITApplication applicationWithBundleID: @"com.apple.itunes"];
        
        ITReference *tracks = [[itunes currentPlaylist] tracks];
        
        /* Note: if player is stopped then current playlist isn't available.
         * You could either test for this in advance (as shown here) or check
         * for nil results after sending the 'get' events. Additional NSError
         * info is also optionally available.
         */
        if ([[[tracks exists] send] boolValue]) {
        
                /*
                 * Note: Apple event IPC is query-based, allowing you to get a
                 * property from all elements at once. This is far quicker than
                 * iterating over elements yourself if there are lots of them.
                 */
                NSArray *names = [[tracks name] getList];
                NSArray *artists = [[tracks artist] getList];
                NSArray *albums = [[tracks album] getList];
                
                int i;
                for (i = 0; i < [names count]; i++)
printf("%-60s %-60s %-60s\n", [[names objectAtIndex: i] UTF8String],
                                                                                
        [[artists objectAtIndex: i] UTF8String],
                                                                                
        [[albums objectAtIndex: i] UTF8String]);
                
        } else
                printf("Current playlist is not available.\n");
        
        [pool drain];
        return 0;
}


HTH

has

[1] Which is a bit like Scripting Bridge, but without the application compatibility problems and with 10.3.9 and 10.4.x support, better documentation and developer tools.
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to