NSAppleEventDescriptor extract image data

Afternoon,

I’m writing a small applescript app in xcode to help manage my music collection. I’m trying to display the artwork from the tracks. I use the following code to get the artwork data from iTunes:

tell application “iTunes”
set track_x to track 17 of playlist “Library”
set artwork_data to data of artwork 1 of track_x
end tell

It returns the data as an NSAppleEventDescriptor. I query to get the class using:

current application’s NSLog(“%@”, class of artwork_data)

Result:
<NSAppleEventDescriptor: ‘JPEG’>

I have tried all kinds of ways to try and extract the data to create an NSImage but I can’t figure it out. I’ve looked at examples for extracting data from NSAppleEventDescriptors that a contain lists etc. I also tried the following, with no luck

set theCode to current application’s NSHFSTypeCodeFromFileType(“rdat’”)
set theData to (current application’s NSAppleEventDescriptor’s descriptorWithDescriptorType:theCode |data|:theData) as data

Any thoughts?

Cheers,

James.

Just get its data:

set theData to theDesc's |data|()
set theImage to current application's NSImage's alloc()'s initWithData:theData

Shane,

Thank you for the quick reply. I have tried implementing your suggestion, and get the following error:

doesn’t understand the “data” message. (error -1708)

Any thoughts?

James.

Try changing it to:

set theData to (current application's NSArray's arrayWithObject:theDesc)'s firstObject()'s |data|()

Shane,

That did the trick! Thank you for everything you do for the community!

Cheers,

James.