Apologies.
I am hoping to be able to reset an array and to set up the array if its not set.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
use script "Dialog Toolkit Plus" version "1.1.0"
use script "PrefsStorageLib" version "1.0.0"
prepare storage for (path to me) default values {theList:{}}
set theList to value for key "theList"
set theTask to value for key "theTask"
if theList is {} then
set accViewWidth to 200
set {theButtons, minWidth} to create buttons {"Close", "More"} button keys {"", "2", "1", ""} default button 2 cancel button 1
if minWidth > accViewWidth then set accViewWidth to minWidth -- make sure buttons fit
set {theField, theTop} to create field "" placeholder text "use comma to separate values" bottom 0 field width accViewWidth extra height 2 --with accepts linebreak and tab
set {buttonName, controlsResults} to display enhanced window "" acc view width accViewWidth acc view height theTop acc view controls {theField} buttons theButtons active field theField initial position {0, 0} --with align cancel button
set theList to controlsResults
set theList to value for key "theList"
end if
set accViewWidth to 400
set {theButtons, minWidth} to create buttons {"reset prefs", "Close", "More"} button keys {"", "2", "1", ""} default button 3 --cancel button 1
if minWidth > accViewWidth then set accViewWidth to minWidth -- make sure buttons fit
set {theField, theTop} to create field "" placeholder text theTask bottom 0 field width accViewWidth extra height 2 --with accepts linebreak and tab
set {taskPopup, popupLabel, theTop} to create labeled popup theList bottom (theTop + 5) popup width 180 max width accViewWidth label text "Set Status:" popup left 75 initial choice theTask
set {buttonName, controlsResults} to display enhanced window "" acc view width accViewWidth acc view height theTop acc view controls {theField, taskPopup, popupLabel} buttons theButtons active field theField initial position {0, 0} --with align cancel button
set {scanSku, theTask} to controlsResults
assign value theTask to key "theTask"
assign value theList to key "theList"
if buttonName is "reset prefs" then
remove value for key "theList"
remove value for key "theTask"
end if
hitting the 'reset prefs" button is working but I’m struggle to set the array. I hoping to be able to type “option1”,“option2” in the first dialog and they become option for the labeled popup in the second window.
You have to convert the comma-delimited string into a list yourself. So:
set {buttonName, controlsResults} to display enhanced window "" acc view width accViewWidth acc view height theTop acc view controls {theField} buttons theButtons active field theField initial position {0, 0} --with align cancel button
set fieldValue to item 1 of controlsResults
set {saveTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {","}}
set theList to text items of fieldValue
set AppleScript's text item delimiters to saveTID
assign value theList to key "theList"