Array into table view?

I’m trying to get a list of data pulled from a sqlite db into a table view. It works fine when I manually type up a list, eg {{hi:“hi”},{hello:“hello”} but not when I create the list dynamically. I do have a restriction so it only outputs one results to eliminate any string errors.

I think I’m going about this in a very overly complicated manner so maybe you know a more efficient way to do this?

The specific error I’m getting is:
-[NSCFString count]: unrecognized selector sent to instance 0x2002cf4a0 (error -10000)

Here is the code:


		set theResult to every paragraph of (do shell script (head & selectQuery & quote))
		set theList to {}
		set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "|"}
		set numTR to 0
		repeat with r in theResult
			if numTR is equal to 0 then
				set dbTaskName to first text item of r
				set dbScheduledFor to second text item of r
				set end of theList to "{taskName:" & quote & dbTaskName & quote & ", scheduledFor:" & quote & dbScheduledFor & quote & "}" as record
			end if
			set numTR to 1
		end repeat
		set AppleScript's text item delimiters to ASTID
		set startOfList to "{"
		set endOfList to "}"
		set theFinalList to startOfList & (theList) & endOfList
		theDataSource's addObjectsFromArray_(theFinalList)
		aPlaceForMyHead's setStringValue_(theFinalList)
		taskTable's reloadData()

Delete these three lines:

       set startOfList to "{"
       set endOfList to "}"
       set theFinalList to startOfList & (theList) & endOfList

And change the following one to :

       theDataSource's addObjectsFromArray_(theList)

Here is the new code:


		set theList to {}
		set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "|"}
		set numTR to 0
		repeat with r in theResult
			if numTR is equal to 0 then
				set dbTaskName to first text item of r
				set dbScheduledFor to second text item of r
				set end of theList to "{taskName:" & quote & dbTaskName & quote & ", scheduledFor:" & quote & dbScheduledFor & quote & "}"
			end if
			set numTR to 1
		end repeat
		set AppleScript's text item delimiters to ASTID
		theDataSource's addObjectsFromArray_(theList)
		aPlaceForMyHead's setStringValue_(theList)
		taskTable's reloadData()

That’s actually what I had originally, but i’m getting:
[BlahAppDelegate tableView:objectValueForTableColumn:row:]: -[NSCFString objectForKey:]: unrecognized selector sent to instance 0x2005ae520 (error -10000)

If I echo theList as a string, I get this:
(
“{taskName:"Task 1", scheduledFor:"2:00:24 PM"}”
)

Whoops. this:

               set end of theList to "{taskName:" & quote & dbTaskName & quote & ", scheduledFor:" & quote & dbScheduledFor & quote & "}"

should be this:

               set end of theList to {taskName: dbTaskName, scheduledFor: dbScheduledFor}

Worked like a charm. Man, I was so close!
So I could start a new thread but I’ll just ask…how would I get the data from a double-clicked row?

First you have to make the columns uneditable (otherwise double-clicking starts editing). Then write an action handler to be called when you double-click. Something like:

on myDoubleClick_(sender)
 set theSel to arrayController's selectedObjects() as list
  -- do your stuff
end myDoubleClick_

Then call the table’s setDoubleAction_ method, probably somewhere like in applicationWillFinishLaunching_:

	tell theTable to setDoubleAction_("displaySelection:")

Huge help as always! Thanks!