Getting and Setting the State of a Switch button cell in a Table View

Hi,

I have a small table view that reads a list of local disks and lists them in one column with a row of button cells next to it (Switches).

I’m trying to get and set the state of the buttons, but am comping up empty. I’m trying this:

if the name of theObject is "disklistdone" then
		close panel window "disklister"
		set watcher to state of button 1 of data column "Watched" of table view "disklisttable" of scroll view "disklistscroll" of window 1
		display dialog watcher --see what I'm getting here
	end if

I’m getting the following:

Can’t make «class staB» of «class butT» 1 of «class datB» “Watched” of «class tabW» “disklisttable” of «class scrV» “disklistscroll” of window 1 into type reference. (-1700)

Any ideas?

Try contents instead of state:

if the name of theObject is "disklistdone" then
		close panel window "disklister"
		set watcher to contents of button 1 of data column "Watched" of table view "disklisttable" of scroll view "disklistscroll" of window 1
		display dialog watcher --see what I'm getting here
	end if
	
	

I am unsure if it will work in this fashion; I have only used this when checking (and setting) checkbox buttons by name in a window (not a table), like this:

if (contents of control sk_button of window "main") is false then -- In this case, sk_button is that button's name 

For setting the buttons, I use 0 (unchecked) and 1 (checked). This repeat reads from a two item list (skip_butts) that is in this format - {{“button_Name”, “0”}, etc.}:

repeat with ab from 1 to 4 --Set buttons to on or off 
		tell window "main" to set contents of button (text item 1 of (item ab of skip_butts) as string) to ((text item 2 of (item ab of skip_butts)) as number)
	end repeat

I hope this helps,

Using Contents or String Value doesn’t help.

Unfortunately, these checkboxes are generated by a repeat loop and aren’t named. that’s why I’m trying to talk to the button as “button 1.” I have also tried:


set watcher to state of control of button 1 of data column "Watched" of disklistdatasource

and


set watcher to state of control of button 1 of data column "Watched" of disklistdatasource

I’m getting the same type of error.

So I’ve wound up with this:

set watcher to content of data cell "watched" of data row 1 of data source "disklist" of table view "disklister" of scroll view "disklistscroll" of window 1

Now I’m getting an NSReceiverEvaluationError (4) which I guess is progress…

OK, Jacques gave the correct answer, I just had to set the variable before closing the window. All is working perfectly!