Tuesday, April 13, 2021

#1 2021-04-02 02:59:58 pm

jcbaxter1975
Member
Registered: 2005-07-13
Posts: 3

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.

Offline

 

#2 2021-04-02 05:15:15 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6613

Re: NSAppleEventDescriptor extract image data

Just get its data:

Applescript:

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2021-04-04 06:48:18 am

jcbaxter1975
Member
Registered: 2005-07-13
Posts: 3

Re: NSAppleEventDescriptor extract image data

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.

Offline

 

#4 2021-04-04 07:04:16 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6613

Re: NSAppleEventDescriptor extract image data

Try changing it to:

Applescript:

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#5 2021-04-04 07:14:09 am

jcbaxter1975
Member
Registered: 2005-07-13
Posts: 3

Re: NSAppleEventDescriptor extract image data

Shane,

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

Cheers,

James.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)