Check Boxes

How would you get the checked state of a check box? In Applescript studio you did this:

if the name of theobject contains “thecheckbox” then
if (string value of button “thecheckbox” of window “SetupWIn”) = “1” then
end if
end if

How would this be translated to ApplescriptObj?

Also how would you go and change the state? In Applescript studio you would do this:

tell button “thecheckbox” of window “SetupWIn”
set integer value to 1
end tell

How would this be translated to ApplescriptObj?

As far as I know, you don’t even need a single line of code for this. All you need to do is declare a property with a variable name that represents the check box you’d like to store the state in (for ex.: theCheckButtonState), and in Interface Builder you just need to right-click and drag from your app delegate’s blue cube to the check box in your window and select the name you defined (theCheckButtonState) for the property in the menu that appears. This way, all you have to do to check the state of the button is to check the value of the property (theCheckButtonState) and you’re good! That’s the magic of ASOC. No line of code necessary but defining a property.

You can push this a bit further by addind a Shared User defaults controller and bind i’s value in the inspector’s bindings section (command-4) and check the bind to check box and select Shared user defaults controller in the menu. Then add values to the Controller key and a name to save it under in the app’s pref in the Model Key Path box and you’re done. This way, storing the state of the check box will be done automatically upon quit and upon relaunch the pref will be read and the state of the check box changed accordingly. Amazing, no?

Model: MacBookPro2,2
Browser: Safari 531.9
Operating System: Mac OS X (10.6)

object’s intValue() -yes 20 characters 1 line, return 1 or 0

and object’s setIntValue_([1 or 0]) to set it