iTunes Artwork and Image Cell

Hi There,

I’m trying to load the itunes artwork to an image cell in a table view without save the artwork in a temp file.

	tell application "iTunes"
		set this_image to data of artwork 1 of current track as picture
	end tell
	set the_table to table view "albums" of scroll view "albums" of window "main"
	set the_data_source to make new data source at end in data sources
	set data source of the_table to the_data_source
	tell the_data_source
			delete data rows
		end try
			delete data columns
		end try
		make new data column at end of data columns with properties {name:"image"}
		set the_row to make new data row at end of data rows
		tell the_row
			set contents of data cell 1 to this_image
		end tell
	end tell
	tell window "main" to update

I get an error “can’t make data (the data of artwork)”

If i save the artwork in a file it works fine.

There’s a way to show the raw data in an image cell withous save it in a temp file?

Thanks for help.


It takes a little doing but isn’t hard. My method uses the scripting bridge which is only available in 10.5 or later. Here’s what you need to do…

  1. Add the ScriptingBridge.framework framework to your project.
  2. Add an iTunes header file to your project so the scripting bridge can control itunes. You need to generate the header file so type this in the Terminal and you will get a file called iTunes.h. Add that file to your project.
  1. Add a new file to your project and make it an “Objective-C class”. Add both the “.h” and “.m” files. Call the new file “iTunesArtworkClass”
  2. make the “.h” file look like this:
  1. make the “.m” file look like this:
  1. Then in applescript you can use this code. I used an image view when I wrote it but you can just pass the data cell as the parameter instead. I didn’t try it with a data cell, but as long as it is an image cell it should work.
set success to call method "addArtworkFromCurrentTrackToObject:" of class "iTunesArtworkClass" with parameter (image view "imageView" of window 1)
log success

Thank you much,

working on your code I made it work but the result is different from my expectations so now I want to try a different approach: use dynamically generated image views inside a scroll view so, if the images are a lot I can scroll down. But all my tries have been a failure.
I’m able to create dynamic image view inside a scroll view but no scroll bars so I have something like:
The goal is to make something like the grid view of albums like iTunes.

Any suggestion is appreciated.