Set radio buttons

Hi everyone,

Im new to ASOC and Xcode (using 4.3), and having a tough time with radio buttons and bindings, despite many hours of googling and watching video tutorials. I did manage to get checkboxes working in the same way Id like to get the radio’s going, but Im stumped on the Radios. Heres my relatively simple scenario:

I have a text file that gives me a variable. Based on that value, Id like to have the radio button be set to the appropriate choice. Its a simple On/Off 2 radio buttons toggling kind of thing. Now, in order to address the radio button in my code, I need a binding, but I don’t know which one I need (Selected Index? Selected Object? Selected Value?). If I know which one, Ill then set the model key path to something like “onOffObj”

Once I have that figured out, I need to work out the command to set it to either On or Off. It will go inside an if block. example:

if myVarFromText is “Enable”
– something like: set onOffObj’s value to “On”
else if myVarFromText is “Disable”
– something like: set onOffObj’s value to “Off”
end if

Ive tried it a million different ways, at this point Im shooting in the dark. Any help would be greatly appreciated!

Hi,

define a property selectedIndex and bind it to selectedIndex of NSMatrix (the radio buttons)
Then setting the property changes the selection


set my selectedIndex to 0 -- or 1

Hi Stefan,

Im not doing something right, still not working. Heres what I did:

Selected the radio buttons, in the bindings tab, I drop down Selected Index, check “Bind to:” and select File’s Owner from the associated drop down menu. Next, in Model Key Path, I filled in onOffObj. Next Im off to my applescript document, where I have two lines:

property onOffObj : missing value
set my onOffObj to 0 – or 1

The radio button remains “On” regardless of whether I change the second line to 1.

Thanks for the help.

the property is not a IBOutlet indicated by the value missing value but a normal property. Set the initial value to o or 1.
The object to bind selectedIndex to must be the script object containing the property, normally the app delegate script

Hi Stefan,

In my "Bind to: " drop down menu, I have only File’s Owner, Application, and Shard User Defaults Controller. Setting the initial value to 1 in my code changes the radio buttons, indicating the code and radio buttons seem to be communicating. I also have checkboxes that are using bindings to “File’s Owner” which work.

My code now looks like this, the first line has an effect, but the second one doesn’t:

property onOffObj : 1
set my onOffObj to 0 – or 1

Now the radio button remains “Off” regardless of whether I have the second line at 1 or 0

Thanks for the assistance with this, I apologize for the rookie questions.

where is the second line placed?

In AppleScriptObjC there is no implicit run handler so put the code in the applicationDidFinishLaunching handler or one of the other initial handlers

The fact that you don’t have “app delegate” as one of the choices in the drop down menu in the bindings inspector, tells me something is wrong. Is the code you’re posting in the app delegate? Did you change the name of that file? Did you start the project by choosing the “Cocoa-AppleScript Application” icon in Xcode?

Ric

That worked! Thanks for your patience and help Stefan, you’re a hero.

Hi Ric,

Im using Xcode 4.3.1. All my new applescript-cocoa files open up without an app delegate. The main 3 files I have on the left sidebar are main.xib, document.xib and document.applescript. Ive been putting my code in the document.applescript file. As Im writing this, I realize (and have now verified) that I had the “document based project” checkbox enabled when making new projects. Not sure what the difference is. Thanks for pointing it out, Ill use the non-document projects from now on since that seems to be what more people and tutorials expect.

for example TextEdit is a document based application. You can handle document files which belong to your application