image cell icon

I want to show in a table view in the first row the icon and in the secon the name of the items of a folder. I’ve tried but always got errors.

set itemData to make new data source at end of data sources with properties {name:“category”}
make new data column at end of data columns of itemData with properties {name:“name”}
make new data column at end of data columns of itemData with properties {name:“image”}
set data source of table view “View” of scroll view “View” of window 1 to itemData

tell application “Finder” to set thisItem to item “Users:myName:Desktop:test.txt”
set myName to name of thisItem
set myImage to ???
append itemData with {{|name|:myName, |image|:myImage}}

The code below will do some of what you want. The way I understand your question though, you want to get the icon for each item and place it in the list next to the name of the item, right? That is quite difficult and you won’t get an easy answer to that here. There have been a handlful of posts regarding icons, none of which provide simple methods of interacting with icons.

To simply create a row and insert an image and text, the following code will work. You must make the column you want the images displayed in an image cell, by dragging an image cell onto the column in the Interface Builder data palette (Panther 10.3.x only). Using this method, you’ll have to create images for all of your potential image “types” and then import them into your project. Create a blank, transparent gif image (“theDefaultImage” below) and insert it into the row any time you want ‘no’ image displayed. I usually create a property for each at the head of my document, and then intialize them at startup. This way I can reference them at any time as their variable name, rather than loading them into the project (and memory) every time I use them. You MUST provide a valid image every time you create a new table row, because you can’t have a null value in an image cell.

(* Define the containers for all of my images *)
property theOtherImage : ""
property theDefaultImage : ""

(* Initialize my images *)
on awake from nib theObject
	set theDefaultImage to load image "default.gif"
	set theOtherImage to load image "other.gif"

	set itemData to make new data source at end of data sources with properties {name:"category"}
	make new data column at end of data columns of itemData with properties {name:"name"}
	make new data column at end of data columns of itemData with properties {name:"image"}
	set data source of table view "View" of scroll view "View" of window 1 to itemData 
end awake from nib

(* Create a new row at the press of the button 'createNewRow' *)
on clicked theObject
	if name of theObject is "createNewRow" then
		tell application "Finder"
			set thisItem to item "Macintosh HD:Library:"
			set theItemName to name of thisItem
		end tell

		set theDataSource to data source of table view "View" of scroll view "View" of window 1 to itemData
		tell theDataSource
			set theRow to make new data row at the end of the data rows
			set contents of data cell "image" of theRow to theOtherImage
			set contents of data cell "name" of theRow to theItemName
		end tell
	end if
end clicked

I hacked this together from some of my projects and didn’t test it in it’s final form. It does contain all of the necessary element to do what you’re trying to do though, so post any problems you’re having and we can help you get them out. You could also modify this to use the append command. Sorry there’s no easier way that I know of.

j

thanks

I want to get the images dynamically, so I have to try something else…