Is there a way to enable to do multiple selection in “choose from List” command??
if so, how can you catch the reactions??
here is the code:
set selectionChoice to choose from list {"Selection A", "Selection B", "Selection C"} with prompt "Please make a selection."
set selectionChoice to selectionChoice as string
if (theInstallCode is equal to "Selection A") is true then
copy "file A" to startup disk - example of work to be done for each selection
else if (theInstallCode is equal to "Selection B") is true then
copy "file B" to startup disk
else if (theInstallCode is equal to "Selection C") is true then
copy "file C" to startup disk
end if
Is there a way so that I can multiple select “Selection A” and “Selection B”??
so that the copying can be done in one go??
set selectionChoice to choose from list {"Selection A", "Selection B", "Selection C"} with prompt "Please make a selection."
set selectionChoice to selectionChoice as string
if (selectionChoice is equal to "Selection A") is true then
copy "file A" to startup disk - example of work to be done for each selection
else if (selectionChoice is equal to "Selection B") is true then
copy "file B" to startup disk
else if (selectionChoice is equal to "Selection C") is true then
copy "file C" to startup disk
end if
set selectionChoice to choose from list {"Selection A", "Selection B", "Selection C"} with prompt "Please make a selection." with multiple selections allowed
set selectionChoice to choose from list {"Selection A", "Selection B", "Selection C"} with prompt "Please make a selection." with multiple selections allowed
--returns a list of selected items
if the number of items in selectionChoice is not equal to 0 then
repeat with thisItem in selectionChoice --repeat with every item selected
set thisItem to thisItem as string
if (thisItem is equal to "Selection A") is true then
--Work with Selection "A"
else if (thisItem is equal to "Selection B") is true then
--Work with Selection "B"
else if (thisItem is equal to "Selection C") is true then
--Work with Selection "C"
end if
end repeat
end if
This works on MacOS 8.6 - I’m not sure if the syntax for the Choose From List
is different in 9+ though I’ll check when I get into work tomorrow.
This will throw an error if the user hits “cancel” (which returns a boolean “false”).
Theorically, you don’t need a repeat loop… Whit 1 run, you know already the value of selected items, so it would be good enough a simple:
if "Selection A" is in contents of selectionChoice then doThis()
if "Selection B" is in contents of selectionChoice then doThisOther()
if "Selection C"...
You’re right - and I knew that. This was pure laziness on my part. Sorry about that.
Again, much better. I should have looked for a better way than just sticking with the original syntax. But you still may run into problems if you have similar items in the list. If your list = [“Winston”,“Winston 1”, “Winston 2”] and the user chose item 1 of this list - you wouldn’t be able to effectively use the statement “is in the contents of” as it is in all 3 items. I’m just saying you would have to be careful not to have items in the list that are too similar.
Not necessary, because you’re not comparing strings, but items into a list. Eg:
set x to {"naniero 1", "naniero 2", "kaka"}
"naniero" is in contents of x
--> false
Effectively, “naniero” is in contents of “naniero the king”, would throw “true”, but you’re not comparing individual strings, but checking for the existence of an item into a list, where each item is checked individually to be equal to the original term “naniero”. Another test:
set x to {"naniero 1", "naniero 2", "kaka"}
"Naniero 1" is in contents of x
--> true
considering case
"Naniero 1" is in contents of x
end considering
--> false