AppleScript – Troubleshooting ‘Choose from List’ with Multiple Selections

applescript

I have a series of AppleScripts which are saved as apps. For simplicity sake let's say the apps are literally named App1, App2, and App3.
I've made a simple list that asks the user to make a selection, then opens that app. It works fine for single selections…

choose from list {¬
    "App1", ¬
    "App2", ¬
    "App3"} ¬
    with prompt "What would you like to do?" with multiple selections allowed and empty selection allowed

if not result is equal to false then activate application (result as string)

But I also need to be able to select multiple apps at the same time and launch them all together (or sequentially).

Currently, if I pick App1 and App3 I get a Choose Application dialog saying "Where is App1App3?" which obviously doesn't exist.

How can I change the code so that it sees the selections as separate apps and launches them correctly?

Best Answer

At the point where you are having a problem, result is a list. Try looping through the items in the list.

set answer to choose from list {¬
    "App1", ¬
    "App2", ¬
    "App3"} ¬
    with prompt "What would you like to do?" with multiple selections allowed and empty selection allowed
if answer is not false then
    repeat with appitem in answer
        activate application appitem
    end repeat
end if