This is probably a stupid question, but I can’t find out how to set the state of a checkbox (switch) to “checked”
i tried
set state of button “switch1” to true
and
set state of button “switch1” to 1
does anyone know the right syntax?
Model: Imac G5
Browser: Safari 412.5, Xcode 2.1
Operating System: Mac OS X (10.4)
Is this for Xcode/AS Studio? If it is I’ll move it to that area.
You probably need a full reference to the button. (There are many ways of doing this.)
set state of button "switch1" of window "main" to 1
The strange thing is that it doesn’t work when I try it like this:
on launched theObject
set state of button "switch1" of window "main" to 1
end launched
but it does work when I attach the action to a button click
if objName is "showhidden" then
set state of button "switch1" of window "main" to 1
end if
Do I need to do it differently if I want the checkbox to be checked at launch?
May I ask why you are using the “on launched” handler to set the status of a checkbox?
Is that the wrong way to do it?
All I want to do is make sure the checkbox is checked (depending on the some factors) once the software has launched. How should I do that?
Hi,
Since I don’t see any further post on your problem I assume it’s still an active issue.
FYI, I wanted to do a similar thing…get the default checkboxes ticked on start-up. But rather than doing it in “on launch theObject block” I had mine performed in “on awake from nib”. Try it! It might just work for you.
Here’s a prototype that you might experiment with if it suits your need. I am assuming that your checkbox is in the window “main”. If not, you will have to reference the container window properly in your code.
on awake from nib theObject
set objectName to the name of theObject as Unicode text
if the objectName is "main" then
tell window "main"
set the state of button "switch1" to 1
end tell
end if
end awake from nib
You can even make the button a toggle button by checking its state initially and activating-deactivating, if need be, as the case may be.
Good luck.
archseed