3

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?

3
  • This seems remarkably similar in intent to apple.stackexchange.com/questions/383193/…
    – Tetsujin
    Commented Feb 28, 2020 at 19:17
  • It is, but the solution didn't work in the end. My real life working script needs about 30 apps in that list, and with the previous solution I had to add SO many does not contain rules to each if/then that it became horribly complex and riddled with errors when I inevitably missed one. So I thought I'd resubmit with a simpler question, and I'm hoping the solution stays almost as simple as the original script I have. I'm hoping that it's just a matter of editing that last line. Commented Feb 28, 2020 at 19:25
  • idk applescript well enough, but in theory, I'd coerce it into a list & iterate it.
    – Tetsujin
    Commented Feb 28, 2020 at 19:26

1 Answer 1

3

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

 

4
  • Thanks! This works great. What does applic do? I assume it's short for application? It looks like a variable but I don't see it defined anywhere. Commented Feb 28, 2020 at 19:53
  • I wanted to use application or item, but these are the names of a classes. So I needed to choose something else. Settled on using appitem for the variable name. Commented Feb 28, 2020 at 19:58
  • Awesome thanks. This is a simplified version of a script I'm trying to write, and it helps tremendously. Next I would like to scale it up to about 30 items in the list. For the multiple selections I would like it to just select a different app rather than run multiple apps sequentially. A solution was posted in the link here but I need a different answer that simply acts on my selection and EXCLUDES all other choices. Any advice would be greatly appreciated. apple.stackexchange.com/questions/383193/… Commented Feb 28, 2020 at 20:26
  • 1
    What a coincidence! I was wrestling with the same problem, and here's the answer! +1 :)
    – Seamus
    Commented Feb 29, 2020 at 7:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .