setting a list to the contents of a one column table?

You can easily set a table to the content of a list, but how do you set a list to the contents of a table?

I have a simple one column table that is editable. I simply want to get the edited list after the user is done editing the table, as a normal list of strings. Instead, what I get is a list with items like this: {|table column 1|:“live”}

Can anyone tell me what I’m doing wrong? This is the first time I’ve tried to use tables, and it’s confusing to me.

This is what I have tried so far:

property reswords : {"live", "mix", "remix", "re-mix", "Unknown Pleasures", "", "", "", "", "", "", "", "", "", "", ""}
property restable : {}

on clicked
	if name of theObject is "resedit" then
		-- button opens a panel with a one column table
		set restable to reswords
		set content of table view "restable" of scroll view "resscroll" of window "respanel" to restable
		display panel window "respanel" attached to window "main"
	else if name of theObject is "resdone" then
		-- button closes the panel with the table, passes it to panel ended handler
		close panel (window of theObject) with result 1
	end if
end clicked

on panel ended thePanel with result theResult
	if theResult is 1 then
		set dataSource to data source of table view "restable" of scroll view "resscroll" of window "respanel"
		set resrows to every data row of dataSource
		set reswords to {}
		repeat with arow in resrows
			copy (content of arow) to the end of reswords
		end repeat
end panel ended

Result: reswords:

{{|table column 1|:"live"}, {|table column 1|:"mix"}, {|table column 1|:"remix"}, {|table column 1|:"re-mix"}, {|table column 1|:"Unknown Pleasures"}, {|table column 1|:""}, {|table column 1|:""}, {|table column 1|:""}, {|table column 1|:"ret"}, {|table column 1|:""}, {|table column 1|:""}, {|table column 1|:""}, {|table column 1|:""}, {|table column 1|:""}, {|table column 1|:""}, {|table column 1|:""}}

Alternate attempt:

on panel ended thePanel with result theResult
	if theResult is 1 then
		set reswords to contents of table view "restable" of scroll view "resscroll" of window "respanel"
	end if
end panel ended

Result: reswords = same as above

Alternate attempt:

on panel ended thePanel with result theResult
	if theResult is 1 then
		tell table view "restable" of scroll view "resscroll" of window "respanel" to update
		set reswords to restable
end panel ended

Result: reswords = the original values of the restable, even if you edit the table (ie, i thought somehow the list restable is supposed to be automatically linked to the table view as long as the name of the variable (restable) is the same as the name of the table view (restable) in IB.

Thank you!

Doh… looks like I answered my own question right after posting this!

However I’d be interested if there were an easier way, without needing the loop or the data source, i.e. to get the list directly from the table. (Using contents of table view, or something like it).

I needed “contents of data cell 1 of arow” since it is a one column table. It should read:

on panel ended thePanel with result theResult
	if theResult is 1 then
		set dataSource to data source of table view "restable" of scroll view "resscroll" of window "respanel"
		set resrows to every data row of dataSource
		set reswords to {}
		repeat with arow in resrows
			copy contents of data cell 1 of arow to the end of reswords
		end repeat
	end if
end panel ended

set theData to contents of every data cell of every data row of data source of table view 1 of scroll view 1 of window "main"

Something this should do the trick. I got it out of the Applescript Studio Terminology Reference under “Data Cell.”

Hope this helps,
Brad Bumgarner, CTA

As per the other thread, you said the code wasn’t working for you. Below is the code that I am using to get the contents of a single column (of a 3-column table):

to GetJobNumbers()
	set theDataSource to the data source of table view "JobNumbers" of scroll view "JobNumbers" of window "Main"
	set theJobNumbers to the contents of data cell "JobNumbers" of data rows of theDataSource
	return theJobNumbers
end GetJobNumbers

-- result: {"12345", "67890", "15973", "35791", ... , "95137", "75319"}

I will ask the obvious questions: Have you named all of your objects in IB? Have you named the scroll view AND table view? Have you named the column in the table view? When you set up your data source did you use the exact same column name for the name of the data source column? When attempting to get the data from the table are you using the same names as set up in IB? Is everything spelled correctly (or at least the same :wink: )?

I ask these questions, not to question your intelligence, but because when I first started using tables, I had a heck of a time getting them to work for me.

Hope this helps,
Brad Bumgarner, CTA