Run multiple actions from selection in list from dialog window

Hello! I’m new to these forums and need some help in writing an Applescript. I want to create a window in which the user can choose some actions to be performed. Eg. If the user selects both “A” and “B”, then ActionA and ActionB will be run. It would be better if instead of a list with selectable items there would be checkboxes. I can’t install the Studio right now, and wanted to know if this can be done with the AppleScript Editor…
Thanks!


set Options to {"A", "B", "C"}
on ActionA()
say "A"
display dialog "Alkaline" buttons {"OK"} default button 1
end ActionA

on ActionB()
say "B"
display dialog "Badger" buttons {"OK"} default button 1

end ActionB

on ActionC()
say "C"
display dialog "Combustion" buttons {"OK"} default button 1

end ActionC

set ListA to (choose from list Options with prompt "Choose items to be spoken. Hold command (⌘) to select multiple letters" with title "I like chocolate" with multiple selections allowed) as text

if ListA is "A" then
ActionA()
end if

if ListA is "B" then
ActionB()
end if

if ListA is "C" then
ActionC()
end if

Welcome to MacScripter.net.

There’s nothing wrong with what you’ve done – it works. :smiley:

. in some cases. :wink: choose from list returns ‘false’ if the “Cancel” button’s clicked, so you need to generate your own “User canceled.” error. Also, since you’re allowing multiple selections, you shouldn’t coerce the result list to text, but leave it as it is and test to see if it ‘contains’ the selected triggers. Finally, it’s considered bad form to intersperse handlers with bits of the implicit ‘run’ handler, so the first line in your script should be moved to join those at the end (or they moved to join it).


on ActionA()
	say "A"
	display dialog "Alkaline" buttons {"OK"} default button 1
end ActionA

on ActionB()
	say "B"
	display dialog "Badger" buttons {"OK"} default button 1
	
end ActionB

on ActionC()
	say "C"
	display dialog "Combustion" buttons {"OK"} default button 1
	
end ActionC

set Options to {"A", "B", "C"}
set ListA to (choose from list Options with prompt "Choose items to be spoken. Hold command (⌘) to select multiple letters" with title "I like chocolate" with multiple selections allowed)

if (ListA is false) then error number -128

if (ListA contains "A") then
	ActionA()
end if

if (ListA contains "B") then
	ActionB()
end if

if (ListA contains "C") then
	ActionC()
end if

Thank you very much! :smiley: Now it works indeed the way it should! And thanks for the welcome as well! :slight_smile: