I need a dialog with a variable number of checkboxes. The number varies with the number of items in a list. For example, on one occasion, there might be 5 items in the list and so five checkboxes. On another occasion there might be 15 items in the list and so 15 checkboxes. The user would check the desired boxes and processing would then be done on the choice.
Is there a way of doing that ? I have tried code like this (the variable myNum can be any integer):
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use script "DialogToolkitPlus" version "1.0.1" -- Yosemite (10.10) or later
set myNum to 5
set Checkboxes to {}
repeat with k from 1 to myNum
set end of Checkboxes to ""
end repeat
set name_list to {"first", "second", "third", "fourth", "fifth"}
set diag_Title to "Test checkboxes"
set accViewWidth to 400
set accViewInset to 0
set {theButtons, minWidth} to create buttons {"Cancel", "Process"} button keys {"c", "p"} default button 2
if minWidth > accViewWidth then set accViewWidth to minWidth
set {theRule, theTop} to create rule 10 rule width accViewWidth
repeat with j from 1 to myNum
set {item j of Checkboxes, theTop} to create checkbox (item j of name_list) left inset 0 bottom (theTop + 5) max width 250
end repeat
set collectvariables to {}
repeat with z from 1 to myNum
copy item z of Checkboxes to end of collectvariables
end repeat
set allControls to {theRule, collectvariables}
set {button_returned, controls_results} to display enhanced window diag_Title button list theButtons acc view width minWidth acc view height theTop acc view controls allControls
I’m getting this error:
error "-[__NSArrayM superview]: unrecognized selector sent to instance 0x608000e5c710" number -10000
I can’t figure out where the problem is. Perhaps it’s in the process of aggregating the checkbox variables into “allControls”. But, I can’t figure out another way of doing it.
Thanks.