I’ve been trying to come up with a solution for the user to only be able to tick ONE of 2 checkboxes.
I set up dialogs that interfere in case both are ticked, but i’d like to make the app UNTICK checkbox 1 when checkbox 2 is TICKED.
so I linked both checkboxes to “on clicked”
and wrote something like this :
On clicked theObject
if name of theObject is "checkbox1"
set state of "checkbox2" to 0
else
if name of theObject is "checkbox2"
set state of "checkbox1" to 0
end if
But it doesnt work … what do you think I’m doing wrong ?
I know theres only something about the state of the box only (and not the physical aspect of it)… not sure how to go about with this …
on clicked theObject
if name of theObject is "checkbox1" then
tell window "main" -- a reference to the parent Ui element of the checkboxes
set state of button "checkbox2" to (not (get state of button "checkbox1" as boolean)) as integer
end tell
else if name of theObject is "checkbox2" then
tell window "main" -- a reference to the parent Ui element of the checkboxes
set state of button "checkbox1" to (not (get state of button "checkbox2" as boolean)) as integer
end tell
end if
end clicked
if name of theObject is "upperCase" then
tell box 2 of tab view item 4 of tab view 1 of window "main" -- a reference to the parent Ui element of the checkboxes
set state of button "lowerCase" of box 2 of tab view item 4 of tab view 1 of window 1 to (not (get state of button "upperCase" as boolean)) as integer
end tell
else if name of theObject is "lowerCase" then
tell box 1 of tab view item 4 of tab view 1 of window "main" -- a reference to the parent Ui element of the checkboxes
set state of button "upperCase" of box 1 of tab view item 4 of tab view 1 of window 1 to (not (get state of button "lowerCase" as boolean)) as integer
end tell
end if
Whatever, I’ll just keep using my dialogs to tell the users “dont fuc**** do that !!”
Thanks anyways … I think I’ve been enough of a pain in the butt
You are always mixing up the referneces. Every UI element must have an unique reference
if name of theObject is "upperCase" then
tell tab view item 4 of tab view 1 of window "main" -- a reference to the parent Ui element of the checkboxes
set state of button "lowerCase" of box 2 to (not (get state of button "upperCase" of box 1 as boolean)) as integer
end tell
else if name of theObject is "lowerCase" then
tell tab view item 4 of tab view 1 of window "main" -- a reference to the parent Ui element of the checkboxes
set state of button "upperCase" of box 1 to (not (get state of button "lowerCase" of box 2 as boolean)) as integer
end tell
end if
Again: It’s strongly recommended to reference the elements by name e.g
tell box “secondBox” of tab view item “Options” of tab view “Settings” of window “main”
I’m using the following method: In one of the initializing handlers I define certain references,
then I don’t have to care about and can use just the variables
property buttonLowercase : missing value
property buttonUppercase : missing value
on awake from nib
tell tab view item 4 of tab view 1 of window "main"
set buttonLowercase to a reference to button "lowerCase" of box 2
set buttonUppercase to a reference to button "upperCase" of box 1
end tell
end awake from nib
if name of theObject is "upperCase" then
set state of buttonLowercase to (not (get state of buttonUppercase as boolean)) as integer
else if name of theObject is "lowerCase" then
set state of buttonUppercase to (not (get state of buttonLowercase as boolean)) as integer
end if