Applescripts ‘‘Choose from list’’ function already allows multiple selections so this may be overkill. This script converts a list into a checked or unchecked list. It also logs the sequence in which each item was checked or unchecked. Uses might include a nice printout of choices, or a menu of option settings, or a record of changes to settings(perhaps add a timestamp?).
Instructions:
Each item on the CHECKLST is either checked or unchecked.
The CHECKLST is updated to display all checked or unchecked choices.
When the user ends the updating cycle, the result of all checked and unchecked items is returned.
Examples outputs below include both the final checklist, and a log of the users choosing sequence. ie: { (result list) , (sequence list) }
Output Example 1:
{{‘’_1. Bird’‘, ‘’_2. Cat’‘, ‘‘√3. Dog’’}, {’‘√3. Dog’', ‘‘false’’}}
– in example 1, dog was checked then the user ended the cycle. The ‘false’ flag indicates the user ended the update cycle.
Output Example 2:
{{‘’_1. Bird’‘, ‘‘√2. Cat’’, ‘‘√3. Dog’’}, {’‘√3. Dog’‘, ‘‘√2. Cat’’, {’‘_1. Bird’', ‘‘√2. Cat’’, ‘‘√3. Dog’’}}}
– in example 2, cat and dog were checked but dog was checked first. Instead of a ‘false’ flag, the checklist itself is used to indicate the user has ended the update cycle.
Output Example 3:
{{‘‘√1. Bird’’,‘’_2. Cat’‘,’‘√3. Dog’‘}, {’‘√1. Bird’‘,’‘√2. Cat’‘,’‘√3. Dog’‘, {’‘√1. Bird’‘,’‘_2. Cat’‘,’‘√3. Dog’‘},’‘_2. Cat’‘, {’‘√1. Bird’‘,’‘_2. Cat’‘,’‘√3. Dog’'}}}
– in example 3, bird and dog were checked, but in a prior cycle all were checked; Cat was unchecked in cycle two. Finalized checklists were used twice to indicate the user went thru two update cycles.
Output Example 4:
{{‘’_1. Bird’‘,’‘_2. Cat’‘,’‘_3. Dog’‘}, {’‘√2. Cat’‘,’‘√1. Bird’‘,’‘_2. Cat’‘,’‘√3. Dog’‘,’‘_1. Bird’‘,’‘_3. Dog’‘, {’‘_1. Bird’‘,’‘_2. Cat’‘,’‘_3. Dog’'}}}
-in example 4, no items were checked in the final result, but in previous activity multiple checking & unchecking occurred.
set myLST to {"Bird", "Cat", "Dog"}
# CONVERT USERS LIST INTO A CHECKLIST:
property CHECKLST : {}
if CHECKLST is {} then
set n to 0
repeat with eachITM in myLST
set n to n + 1
set end of CHECKLST to "_" & n & "." & space & item n of myLST
end repeat
end if
# CHECK OR UNCHECK LIST ITEMS:
property CHOSN : {}
property SEQUNCE : {}
property processComplete : false
repeat while processComplete is false
set CHOSN to (choose from list CHECKLST with prompt "Check or Uncheck Items" default items CHOSN OK button name {"Update"} cancel button name {"Done"}) as text
if CHOSN is "false" then
--set end of SEQUNCE to CHOSN --uncomment this to log ''false'' at the end of a cycle, ie:{"√1. Cat", "√2. Dog", "false"}
set end of SEQUNCE to CHECKLST --or uncomment this to log the full result at the end of a cycle , ie:{"√1. Cat", "√2. Dog", {"√1. Cat", "√2. Dog", "_3. Bird"}}
set processComplete to true
end if
repeat with n from 1 to count of CHECKLST
set eachOPT to item n of CHECKLST as text
if eachOPT is CHOSN then
if character 1 of (eachOPT as text) is "_" then
set item n of CHECKLST to "√" & items 2 thru -1 of eachOPT
else if character 1 of (eachOPT as text) is "√" then
set item n of CHECKLST to "_" & items 2 thru -1 of eachOPT
end if
set end of SEQUNCE to item n of CHECKLST
end if
end repeat
end repeat
set processComplete to false
# DISPLAY REPORT:
set rprt to "You chose:" & return
repeat with eachITM in CHECKLST
set rprt to rprt & eachITM & return
end repeat
display dialog rprt
return {CHECKLST, SEQUNCE}