Scripting Bridge question
Scripting Bridge question
- Subject: Scripting Bridge question
- From: email@hidden
- Date: Thu, 15 Nov 2007 03:26:15 +0100
I'm playing around with iTunes and the new scripting bridge in
Leopard, and I'm having trouble setting the image of an NSImageView to
the artwork of the current track.
Using the old NSAppleScript way, this works:
NSData *data = (NSData*) [[[[NSAppleScript alloc]
initWithSource:@"tell application \"iTunes\" to return data of artwork
1 of current track"] executeAndReturnError:nil] data];
NSImage *image = [[NSImage alloc] initWithData: data];
[myImageView setImage:image];
So I figured this would be the exact same thing, using Script Bridge:
iTunesApplication *iTunes = [SBApplication
applicationWithBundleIdentifier:@"com.apple.iTunes"];
iTunesTrack *current = [iTunes currentTrack];
iTunesArtwork *artwork = [[current artworks] objectAtIndex:0];
NSImage *image = [[NSImage alloc] initWithData:(NSData *) artwork];
[myImageView setImage:image];
But all I get is a crash:
2007-11-15 03:11:42.056 bridge[4960:10b] *** -[ITunesArtwork length]:
unrecognized selector sent to instance 0x13066510
2007-11-15 03:11:42.058 bridge[4960:10b] An uncaught exception was raised
2007-11-15 03:11:42.059 bridge[4960:10b] *** -[ITunesArtwork length]:
unrecognized selector sent to instance 0x13066510
2007-11-15 03:11:42.059 bridge[4960:10b] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason: '***
-[ITunesArtwork length]: unrecognized selector sent to instance
0x13066510'
I think the problem is iTunesArtwork is not NSData, but an NSImage:
@property (copy) NSImage *data; // data for this artwork, in the form
of a picture
How can I read this picture as data, in order to create an NSImage
imageWithData? I tried with [[[current artworks] objectAtIndex:0]
data] and [myImageView setImage:(NSImage *)artwork] to no avail.
Thanks.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden