Hi Everyone,
I posted a similar question over at MacScripter and it was suggested that I pop over here to ask the same basic question, Is there anyway to get a UI Element into a Myriad Tables layout that will act like a 4th button?
Here is my code:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"
use framework "AppKit"
use script "Myriad Tables Lib" version "1.0.9"
property theCheckbox : missing value
property thePopup : missing value
property theAccessoryView : missing value
set bobB to "Apple, Orange"
set carB to "Peach, Plum, Apple"
set chrisT to "Orange, Pineable, Mango, Cherry, Black Berry, Passion Fruit, Apple, Grape, Kiwi, Nectarine, Peach, Plum"
set danB to "Nectarine, Cherry, Apple"
set jamesB to "Orange, Pineable, Mango"
set johnS to "Kiwi, Apple, Grape"
set rayC to "Apple, Orange, Passion Fruit"
set rudyC to "Grape, Orange"
set shanS to "Orange"
set xC to "Apple"
-- This table has a column of combo boxes
set theData to {{"Chris Tierney", chrisT, true, "1"}, {"Bob Black", bobB, true, "1"}, {"Carmen Brown", carB, true, "1"}, {"Dan Brown", danB, true, "1"}, {"Ray Coz", rayC, true, "1"}, {"James Brown", jamesB, true, "1"}, ¬
{"John Smith", johnS, true, "1"}, {"Rudy Cox", rudyC, true, "1"}, {"Shannon Smith", shanS, true, "1"}, {"Xavier Crux", xC, true, "1"}}
set checkUncheck to "Uncheck"
repeat
if current application's NSThread's isMainThread() as boolean then
my createCheckBoxMainThread:{"Zero Label Count", "checkboxClicked:"}
my buildAccessoryViewMainThread:{theCheckbox}
else
my performSelectorOnMainThread:"createCheckBoxMainThread:" withObject:{"Zero Label Count", "checkboxClicked:"} waitUntilDone:true
my performSelectorOnMainThread:"buildAccessoryViewMainThread:" withObject:{theCheckbox} waitUntilDone:true
end if
set myTable to make new table with data theData editable columns {3, 4} column headings {"Person", "Fruit", "", "# of Labels"} with prompt "Print Labels For:" with title "Label Printing Options" with empty selection allowed
modify table myTable extra button name checkUncheck accessory view theAccessoryView
set theAccessoryView to missing value
set theResult to display table myTable
set theState to theCheckbox's state() as boolean
set theCheckbox to missing value -- to avoid error messages when saving
if button number of theResult is 2 then
if theState is true then
set theData to {{"Chris Tierney", chrisT, true, "0"}, {"Bob Black", bobB, true, "0"}, {"Carmen Brown", carB, true, "0"}, {"Dan Brown", danB, true, "0"}, {"Ray Coz", rayC, true, "0"}, {"James Brown", jamesB, true, "0"}, ¬
{"John Smith", johnS, true, "0"}, {"Rudy Cox", rudyC, true, "0"}, {"Shannon Smith", shanS, true, "0"}, {"Xavier Crux", xC, true, "0"}}
end if
set trueFalse to item 3 of item 1 of theData
if trueFalse is true then
repeat with i from 1 to (count theData)
set item 3 of item i of theData to false
end repeat
set checkUncheck to "Check"
else
repeat with i from 1 to (count theData)
set item 3 of item i of theData to true
end repeat
set checkUncheck to "Uncheck"
end if
else
if button number of theResult is 1 then
return
end if
end if
end repeat
on createCheckBoxMainThread:theArg
set {theTitle, theAction} to theArg as list
-- build a checkbox
set my theCheckbox to current application's NSButton's alloc()'s initWithFrame:{{10, 10}, {150, 18}}
tell theCheckbox
its setButtonType:(current application's NSSwitchButton)
its setTitle:theTitle
its setTarget:me
its setAction:theAction -- a handler in this script
end tell
end createCheckBoxMainThread:
on buildAccessoryViewMainThread:theControls
set my theAccessoryView to current application's NSView's alloc()'s initWithFrame:{{0, 0}, {160, 60}}
repeat with aControl in theControls
(theAccessoryView's addSubview:aControl)
end repeat
end buildAccessoryViewMainThread:
-- this is called when the checkbox is clicked
on checkboxClicked:sender
-- how to make this change all the values in column 4 to 0's and then show the dialog again?
end checkboxClicked:
What I would like to be able to do, is take the values in the 4th column and set them all to zero in a single click. I am guessing/hoping there might be a way, using the on checkboxClicked:sender handler to do this, but I can not think of how. If you run my code, you will see that I am already using the 3rd button that MT provides to check/uncheck the checkboxes in column 3.
Thanks!