NSMatrix - How do I preselect a radio button

NSMatrix

I have been trying to preselect a radio button, and cannot figure out a way to do it in AppleScriptObjC.

I also tried to get the value of the selected radio button instead of the index, but could not make that work.

I can get the selectedIndex, but not the text value ?

I just tried this, but pretty much knew it was not going to work…

set whichPriority to get current row of matrix “aArrangePriority”

This does not seem to work in AppleScriptObjC, what am I missing ?

http://macscripter.net/viewtopic.php?id=13131

set current row of matrix “MatrixName” of window “WindowName” to 1
get current row of matrix “MatrixName” of window “WindowName”
get name of current cell of matrix “MatrixName” of window “WindowName”
set enabled of cell “CellName” of matrix “MatrixName” of window “WindowName” to false

Here’s a message I left Craig

AppleScriptObjC in Xcode Part 4 - Saving, Updating & Deleting

http://macscripter.net/viewtopic.php?id=30359

Craig,

You refer to setTheStatus_ , and I tried to find :

On setTheStatus_(thisBook’s valueForKey_(“theStatus”))

But could not find the handler in any of the five documents.

I have been trying to preselect a radio button, and cannot figure out a way to do it.

I created a binding on the elementIndex to a variable. If I change the selected radio button manually I can get the selectedIndex and display it, but I can’t for example select the 3rd radio button while it loads the page.

I also tried to get the value of the selected radio button instead of the index, but could not make that work

I would like to save the selected radio button to a plist, then reload it the next time I launch.

I would like to trigger a script when a different radio button is selected. I am not sure if I will have to select each radio button individually and control drag to the app delegate, or whether you can select all three and do the control drag.

Thanks for any help you can provide…

Bill Hernandez
Plano, Texas

Hi,

the appropriate ObjC method to select a cell is

NSMatrix *matrix; [matrix selectCellAtRow:2 column:0];

Hi Bill,

“theStatus” is the property bound to the matrix. “setTheStatus” is the correct way to set the value.
There is a video on my blog explaining bindings and key value coding.

You can override this method in your file to intercept when the value of the matrix has changed. You would
execute the script from there.


on setTheStatus_(value)
  -- do stuff here but make sure to set the value
  set theStatus to value
end

hth,

Craig

Like Stefan said:

selectCellAtRow_column_(0, 0)

It is 0 indexed like everything ASOC

PS:

If the matrix is single-row, I’d prefer to assign tags to the cells and select them with

selectCellWithTag_(0)

I tried that, it was confusing and I thought dodgy, it is indexed beginning 1 but ending 0.

If this is an answer to my post #5:
You have to assign each single tag to each single cell in Interface Builder

Ahhh, OK thanks.

Thanks for all the great replies…

aArrangePriority’s selectCellAtRow_column_(1, 0) – This works great…

set x to (aArrangePriority’s selectedRow())
display dialog ("Selected Row is = " & x as string) – This works great…

set x to (aArrangePriority’s selectedCell()) – THIS DOES NOT WORK ?
display dialog (item 1 of x) as string

Bill Hernandez
Plano, Texas

You’re asking for a cell, which is not a list (so you don’t need “item 1 of…”) and can’t be coerced to a string. Perhaps you want something more useful, like the title of the selected cell:

		set x to (aArrangePriority's selectedCell()'s |title|()) 
		display dialog x as string

Shane,

At first I wondered how you came up with :

set x to (aArrangePriority's selectedCell()'s |title|()) display dialog x as string
I had looked at Mac Dev Center: NSMatrix Class Reference

and did not find, your answer, but then I broke it down to :

set x to (aArrangePriority's selectedCell()) -- get the cell reference set y to x's |title|() -- get the title for the cell reference display dialog ("Cell Title : " & y)
and realized that all I had was the cell reference, and I had not gone far enough…

AWESOME, Thank You !

Bill Hernandez
Plano, Texas

How would you get the title of every selected cell if you allow multiple selections?

selectedCells() , this will return the labels I believe, try the usual way, it may return a list.