AppleScript 'choose from list'. How can I run a different command if multiple sections are chosen?

I have an AppleScript which manages my home made After Effects render farm. The farm is made up of three render machines.


The script asks the user to make a selection of what machine(s) they want to render on. It takes their choice(s) and runs an external AppleScript app depending on what choice(s) they made.

Each external AppleScript app runs a command which starts an After Effects render using ExtendScript like this…


set scriptfile to (POSIX file ("/Applications/Render Farm/Scripts/jsx/render_1.jsx"))
tell application "Adobe After Effects 2020"
    DoScriptFile scriptfile
end tell


The JSX file referenced above tells After Effects to start a render on Render Machine 1. The idea of the master script is that the user can select multiple render machines and start them all rendering at once.


set Options to {"Render Node 1", "Render Node 2", "Render Node 3"}

        set ListA to (choose from list Options with prompt "Choose items" with title "Select Stuff" with multiple selections allowed)

   if (ListA contains "Render Node 1") then
        tell application "Render Node 1 App" to activate
    end if

    if (ListA contains "Render Node 2") then
        tell application "Render Node 2 App" to activate
    end if

    if (ListA contains "Render Node 3") then
        tell application "Render Node 3 App" to activate
    end if


My script allows multiple choices to accomplish this, but I hate how sequential it is. After Effects has to receive the first AppleScript command, then run the JSX command which ssh's into the render machine, then it opens the aerender command line program multiple times per machine (each instance can take about 10-15 seconds to open). Only after the last aerender instance has opened is After Effects finally ready to listen for another AppleScript command and do it all over again for the second machine.


However, I have a different JSX command that can start a render on all render machines at the same time from within After Effects with no waiting around. I also have other ones that can start a render on Render Node 1 & 2, Render Node 1 & 3, and Render Node 2 & 3 (basically a different script for each combination.


I would like to do the same thing within my AppleScript master script. But I don't want to display a list of every possible combination, I want something that works more elegantly.


What I would like is to modify the master script so that if, for example, two selections are detected then it doesn't run two scripts, it just runs a different script.


Something like this, but with working syntax…


if (ListA contains "Render Node 1" and "Render Node 2") then
        tell application "Render Node 1 & 2 App" to activate
    end if


When I run that, I get the error "Can’t make "Render Node 2" into type boolean." But surely there's a way to accomplish this?


It also has to work intelligently. If I choose "Render Node 1" and "Render Node 3" it should ONLY open the application "Render Node 1 & 3 App". I don't want it to also open "Render Node 1 App" or "Render Node 1, 2 & 3 App".

Posted on Feb 28, 2020 1:10 PM

Reply
Question marked as Top-ranking reply

Posted on Mar 2, 2020 12:12 PM

If it gets too unwieldy, switch to a binary map.


Save your apps using a 3-digit numbering scheme such that:


100.app > machine 1 only

010.app > machine 2 only

001.app > machine 3 only

110.app > machines 1 and 2

101.app > machines 1 and 3

011.app > machines 2 and 3


Now you just need to:


set appname to ""


set Options to {"Render Node 1", "Render Node 2", "Render Node 3"}

set ListA to (choose from list Options with prompt "Choose items" with title "Select Stuff" with multiple selections allowed)


if ListA contains "Render Node 1" then

set appname to "1"

else

set appname to "0"

end if


if ListA contains "Render Node 2" then

set appname to appname & "1"

else

set appname to appname & "0"

end if


if ListA contains "Render Node 3" then

set appname to appname & "1"

else

set appname to appname & "0"

end if


set appname to appname & ".app" as text

tell application appname to activate


The idea here is that you simply build a string of 0s and 1s depending on whether the corresponding app should launch. By the end of the if statements, you have a string that matches one of the corresponding apps.


4 replies
Question marked as Top-ranking reply

Mar 2, 2020 12:12 PM in response to Mark Paterson

If it gets too unwieldy, switch to a binary map.


Save your apps using a 3-digit numbering scheme such that:


100.app > machine 1 only

010.app > machine 2 only

001.app > machine 3 only

110.app > machines 1 and 2

101.app > machines 1 and 3

011.app > machines 2 and 3


Now you just need to:


set appname to ""


set Options to {"Render Node 1", "Render Node 2", "Render Node 3"}

set ListA to (choose from list Options with prompt "Choose items" with title "Select Stuff" with multiple selections allowed)


if ListA contains "Render Node 1" then

set appname to "1"

else

set appname to "0"

end if


if ListA contains "Render Node 2" then

set appname to appname & "1"

else

set appname to appname & "0"

end if


if ListA contains "Render Node 3" then

set appname to appname & "1"

else

set appname to appname & "0"

end if


set appname to appname & ".app" as text

tell application appname to activate


The idea here is that you simply build a string of 0s and 1s depending on whether the corresponding app should launch. By the end of the if statements, you have a string that matches one of the corresponding apps.


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

AppleScript 'choose from list'. How can I run a different command if multiple sections are chosen?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.