Just for completeness here is the solution to getting the sorted item in a table.
the newFilepath variable is retrieved from an open file dialog and then we get the filename and icon
set newFilename to do shell script ("basename " & quoted form of newFilepath)
set theIconImage to NSWorkspace's sharedWorkspace()'s iconForFile_(newFilepath)
Then - instead of accessing theData variable (which is bound to the array controller’s content) we ask the array controller itself for its arranged objects, and as the name suggests, that is the sorted array.
Then we get the objectAtIndex which is the particular selected object (or the record’s item) in the Array. And ask it for it’s valueForKey_(“sourcefiles”) which is the key in the array containing another array which is the record of items displayed in table 2. This can then be added to with a new record for the new row we want to add to table 2.
if actualSelectedRow > 0 then
set indexnum to FileSet's selectionIndex()
set theOldArraysValues to FileSet's arrangedObjects()'s objectAtIndex_(indexnum)
set theOldTableValues to theOldArraysValues's valueForKey_("sourcefiles")
set theNewTableValues to {{fileicon:theIconImage, filename:newFilename, pathtofile:newFilepath}} & theOldTableValues
theOldArraysValues's setValue_forKey_(theNewTableValues, "sourcefiles")
end if
All along I was sure this would never work - that I would have to create an array object first to send to the Array Controller’s Array. But, as Shane suggested, it seems we can use a plain old applescript record which we AS folks all know and love.
Now I have two tables connected with bindings using about ten lines of code, and only the code needed to add items to them! This creates a “Source List” style of app where data in the right table is tied to the “source” items in left table.
After years of struggling with two tables in ASS, this is a miracle, to me any ways. And being able to write one line of code to get the file’s icon without needing a separate OBJ-C class file is cool too.
Thanks everyone for helping me to solve this.
I already posted the new sample app but here it is:
http://rdutoit.home.comcast.net/~rdutoit/pub/two_bound_tables_sample.zip
Rob