Set state of multiple objects

From the Apple Documention on “set”:

set x to {8, 94133, {firstName:"John", lastName:"Chapman"}}
set {p, q, r} to x
(* now p, q, and r have these values: 
                p = 8
                q = 94133
                r = {firstName:"John", lastName:"Chapman"} *)
set {p, q, {lastName:r}} to x
(* now p, q, and r have these values: p = 8
                                      q = 94133
                                      r = "Chapman" *)

Now, I’m wishing to do the same basic thing, cept I want to set the state of multiple buttons (check boxes) to 0.

This is my code:

on clicked theObject
	if the name of theObject = "advanced" then
		set panelWIndow to window "advancedSettings"
		display panel panelWIndow attached to window "main"
	else if the name of theObject = "applySettings" then
		close panel (window of theObject) with result 1
		--Insert Program Switch Assignment Here--
	else if the name of theObject = "bfloat" then
		set state of button {"bshort", "buchar"} of window "main" to 0
 	end if
end clicked

I receive the following error:

The code works as expected if only a single button is listed (set state of button “buchar” of window “main”…).I’m sure it’s some silly syntax mistake I’m making, I’m new to applescript. But if anyone could point me in the right direction I’d appreciate it.

edit I realize the error code means “cannot make into expected type”…not sure what to do about it though.

hmm - seems likte this is an AppleScritp Studio/Xcode question? There is a separate forum for this here:
http://bbs.applescript.net/viewforum.php?id=3

to your question … maybe something like this would work for you:

tell (every button of window “main” whose name starts with “b”) to set it’s content to 0

I was unsure of which was the more appropriate forum :stuck_out_tongue:

But thank you! This snippet worked:

else if the name of theObject = "bfloat" then tell ¬ (every button of window "main" whose name is not "bfloat") ¬ to set it's state to 0

Moving to AppleScript Studio forum.

(Also changed code tags to applescript tags.)

hi krunk,

here another solution for setting multiple buttons from one script line - an equivalent to your example:


tell window "main"
	set {state of button "bshort", state of button "buchar"} to {0, 0}
end tell