xcoderadio-buttonapplescriptapplescript-objc

How to program radio buttons in Cocoa Applescript (ApplescriptObjC)


So right now I have built a user interface on Xcode and I am scripting AppleScriptObjC.

I have 4 radio buttons on my interface. How to I program them? This is my current code:

-- IBOutlets
property window : missing value
property question1Radio1 : missing value
property question1Radio2 : missing value
property question1Radio3 : missing value
property question1Radio4 : missing value
property enterButton : missing value

on applicationWillFinishLaunching_(aNotification)
    -- Insert code here to initialize your application before any files are opened 
end applicationWillFinishLaunching_

--Radio button script here

on applicationShouldTerminate_(sender)
    -- Insert code here to do any housekeeping before your application quits 
    return current application's NSTerminateNow
end applicationShouldTerminate_

This is the code I just tried but wouldn't work

    -- IBOutlets
property window : missing value
property question1Radio1 : missing value
property question1Radio2 : missing value
property question1Radio3 : missing value
property question1Radio4 : missing value
property enterButton : missing value

on applicationWillFinishLaunching_(aNotification)
    -- Insert code here to initialize your application before any files are opened 
end applicationWillFinishLaunching_

on buttonClicked_(sender)

    if question1Radio1 = false as boolean then display alert "Works"

end buttonClicked_

on applicationShouldTerminate_(sender)
    -- Insert code here to do any housekeeping before your application quits

    return current application's NSTerminateNow
end applicationShouldTerminate_

Solution

  • I would suggest only using an Outlet for the matrix as a whole, not the 4 individual buttons. Then, you can connect the matrix, and in the send action of the button (or of the matrix if you like), get the index of the matrix to act on it. Such as:

    on buttonWasClicked_(sender)        
        set theCol to (questionMatrix's selectedColumn()) as integer
        set theRow to (questionMatrix's selectedRow()) as integer
    
        if {theCol, theRow} is {0,0} then 
        -- do stuff
        else if …
    

    Your questions is pretty general. I can't tell what parts of the process you do and don't know. So, continue to clarify in comments or revising your question so we can supply what you need.