Getting Finder's File Icon Image in ASOC Project

Is there a way to get the iTunes or Finder file icon image from an iTunes library audio file ?

I’m loading audio files into my ASOC project, and I’ve tried to get the audio file image as displayed in itunes or Finder with the below code, but this only gives me the generic operating system audio file icon, and not the audio files artwork as displayed n the Finder window.


set theSharedWorkspace to current application's NSWorkspace's sharedWorkspace()
set theAudioFileIcon to theSharedWorkspace's iconForFile:(theAudioFilePath)

Is there any way other than scripting iTunes to get the audio file or album artwork image ?
How does Finder display the album artwork image ?
And is there any way of getting that image from Finder ?

Thanks in advance

Mark

There is an iTunesLibrary framework, a;thought I believe your app has to be code-signed with a developer certificate to access it. Otherwise I think you’re stuck with scripting iTunes.

I wasn’t aware of the iTunesLibrary framework, so I’ll definitely check out that option.
As you suggesting that the Finder may be using the iTunesLibrary framework itself, to display the iTunes artwork when showing the audio files in it’s own window.
If so, then that answers my question about the Finder’s ability to show iTunes artwork.

After a bit more searching online, I’m starting to agree with you that scripting iTunes may be the only other option, although I was hoping to avoid this, as I don’t like activating and accessing other visible Apps from my Xcode projects.
And as a rule, I only like scripting faceless background applications, which don’t distract the user from the key App.

Thanks for the advice.

Mark

Further to Shane’s good advice.

I thought I would post my findings on the iTunesLibrary.framework for others who may be interested.

You can indeed use and test in debug development mode with the iTunesLibrary.framework in an ASOC Xcode project.
But as Shane stated, you must code sign your compiled app before it will work with the framework.

to access the classes in the framework, you must first import it into your Xcode project, and to do this you must highlight the topmost project item in the left project file browser in Xcode, and then select the Apps TARGETS item, and not the App’s PROJECT item.
Next select the “General” tab at the top at the Xcode window, and scroll down to the “Linked Frameworks and Libraries” disclosure triangle, then click the triangle and then the displayed “+” symbol.
This will show a window where you can select and add Frameworks and Libraries to your project, but as you’ll notice the iTunesLibrary.framework is not listed, so you have to click the “Add Other…” button and navigate to /Library/Frameworks/iTunesLibrary.framework. and double click this file to add the framework to your project.

The first thing you have to do in order to work with the framework classes, is to create the ITLibrary parent class object, and I’ve posted a simple example below of creating this and then creating a ITLibArtwork class object, which you can then use to get the NSImage file icon of any media file.


try
    -- Create the Parent ITLibrary class object
    set theiTunesLibrary to current application's ITLibrary's libraryWithAPIVersion:("1.0" as text) |error|:(missing value)

    -- Create the ITLibArtwork class object for a valid NSURL class object of a media file 
    set theAudioFileArtwork to theiTunesLibrary's artworkForMediaFile:(theAudioFileURL)

    -- Create an NSImage class object from the ITLibArtwork's image() instance method
    set theAudioFileImage to theAudioFileArtwork's image() <-- Returns an NSImage
on error
    -- An Error Occurred
end try

In the first line in the above code you can set the APIVersion installed on your system, I have version “3.0” installed on my system, although any version from “1.0” to “3.0” works for me.
You can check the installed version by navigating to the iTunesLibrary.framework file in Finder, then double clicking the framework file to reveal it’s contents, and then double clicking the Resources folder to reveal the versions.plist file.
You can also call the apiMajorVersion() and apiMinorVersion() instance methods of the ITLibrary, to get the current installed version, although you have to create an instance of the ITLibrary first before being able to use these methods.

Here’s a link to the iTunesLibrary.framework’s documentation, as there’s a lot of other stuff in there worth checking out.
https://developer.apple.com/library/mac/documentation/iTunesLibrary/Reference/iTunesLibraryFrameworkReference/

Regards Mark