Jonathan,
I'll need to be able to read the image from AAC files as well.
I found an AppleScript by Mark Knopper - but I'm having a problem with it. I get this error: ""Can't get item 1 of {}.""
here is the script: (any help would be great!!)
// The script returns a two-item list {artworkData, artworkFormat}. // The data contains a spurious 222 byte header followed by the raw JPEG, PNG etc. data. // The format is a string that could be "JPEG" or "PNG".
NSAppleScript *getArtScript; NSAppleEventDescriptor *descriptor; NSString *searchString, *pictureFormat; NSData *pictureData, *pictureDataWithoutHeader; NSRange pictureRange; int picture_length; NSImage *pictureImage; NSDictionary *errorInfo;
//getArtScript = [[NSAppleScript alloc] initWithSource:[NSString stringWithFormat:@"with timeout of 5 seconds \n\ tell application \"iTunes\" \n\ set these_tracks to (search playlist \"Library\" for \"%@\") \n\ set theTrack to item 1 of these_tracks \n\ set artworkData to (data of artwork 1 of theTrack) as picture \n\ set artworkFormat to (format of artwork 1 of theTrack) as string \n\ return (artworkData, artworkFormat) \n\ end tell \n\ end timeout",searchString]]; getArtScript = [[NSAppleScript alloc] initWithSource:[NSString stringWithFormat:@"with timeout of 5 seconds \n tell application \"iTunes\" \n set these_tracks to (search playlist \"Library\" for \"%@\") \n set theTrack to item 1 of these_tracks \n set artworkData to (data of artwork 1 of theTrack) as picture \n set artworkFormat to (format of artwork 1 of theTrack) as string \n return (artworkData, artworkFormat) \n end tell \n end timeout",searchString]];
descriptor = [getArtScript executeAndReturnError:&errorInfo];
if (descriptor==nil) { NSLog([errorInfo description]); return; // not much point going on from here. } pictureFormat = [[descriptor descriptorAtIndex:2] stringValue]; pictureData = [[descriptor descriptorAtIndex:1] data]; picture_length = [pictureData length];
// leave out the first 222 bytes. pictureRange = NSMakeRange(222, (picture_length-222)); pictureDataWithoutHeader = [pictureData subdataWithRange:pictureRange];
pictureImage = [[[NSImage alloc] initWithData:pictureDataWithoutHeader] autorelease]; // finally got an NSImage. [coverArt setImage:pictureImage];
[getArtScript release];
On 6-Jun-05, at 8:07 PM, Jonathan del Strother wrote:
On 6 Jun 2005, at 23:01, Jerry Brace wrote:
Could someone give me some tips on how to get iTunes artwork via Cocoa + AppleScript? I'm trying to get it from the currently playing song and place it in a NSImageView.
I've found ID3Tag to be extremely useful for this...
|