Applescript using if then statements and choose from list





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm working on a course selection script and each person should only be able to select three courses. I am having issues figuring out how to repeat choose from list if the user selects less than or more than three courses, and only proceed if three choices are selected. Converting the choices from the list to string should work however nothing happens after choosing from list



set theClassList to {"Math ", "English ", "Science ", "I&S ", "Design "}

repeat

set theClass to choose from list theClassList with prompt "Select three courses" with multiple selections allowed

set theClassString to theClass as string

if words in theClassString ≠ 3 then

display dialog "Please select three courses"
exit repeat

else if words in theClassString = 3 then
display dialog "Ok"

end if
end repeat









share|improve this question





























    0















    I'm working on a course selection script and each person should only be able to select three courses. I am having issues figuring out how to repeat choose from list if the user selects less than or more than three courses, and only proceed if three choices are selected. Converting the choices from the list to string should work however nothing happens after choosing from list



    set theClassList to {"Math ", "English ", "Science ", "I&S ", "Design "}

    repeat

    set theClass to choose from list theClassList with prompt "Select three courses" with multiple selections allowed

    set theClassString to theClass as string

    if words in theClassString ≠ 3 then

    display dialog "Please select three courses"
    exit repeat

    else if words in theClassString = 3 then
    display dialog "Ok"

    end if
    end repeat









    share|improve this question

























      0












      0








      0


      1






      I'm working on a course selection script and each person should only be able to select three courses. I am having issues figuring out how to repeat choose from list if the user selects less than or more than three courses, and only proceed if three choices are selected. Converting the choices from the list to string should work however nothing happens after choosing from list



      set theClassList to {"Math ", "English ", "Science ", "I&S ", "Design "}

      repeat

      set theClass to choose from list theClassList with prompt "Select three courses" with multiple selections allowed

      set theClassString to theClass as string

      if words in theClassString ≠ 3 then

      display dialog "Please select three courses"
      exit repeat

      else if words in theClassString = 3 then
      display dialog "Ok"

      end if
      end repeat









      share|improve this question














      I'm working on a course selection script and each person should only be able to select three courses. I am having issues figuring out how to repeat choose from list if the user selects less than or more than three courses, and only proceed if three choices are selected. Converting the choices from the list to string should work however nothing happens after choosing from list



      set theClassList to {"Math ", "English ", "Science ", "I&S ", "Design "}

      repeat

      set theClass to choose from list theClassList with prompt "Select three courses" with multiple selections allowed

      set theClassString to theClass as string

      if words in theClassString ≠ 3 then

      display dialog "Please select three courses"
      exit repeat

      else if words in theClassString = 3 then
      display dialog "Ok"

      end if
      end repeat






      applescript






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 4 at 4:56









      KevinKevin

      32




      32
























          2 Answers
          2






          active

          oldest

          votes


















          0














          It's a clever idea to count the words in the theClassString (which would be done using number of words in theClassString, instead of simply words in theClassString). This would work the majority of the time, until a user includes "I&S" as one of their options, which sadly counts as two words, "I" and "S", since the ampersand is not a word character.



          You also had your exit repeat in the wrong half of the if...then...else block, since you want to break the loop when the user selects 3 courses, not when they fail to select 3 courses.



          Rather than attempting to coerce the result of the list selection into a string, you ought to just count the number of items in the result, which can be done in one of three ways:




          1. count theClass

          2. length of theClass

          3. number in theClass


          Here's a reworked version of your script:



          property theClassList : {"Math ", "English ", "Science ", "I&S ", "Design "}
          property text item delimiters : linefeed

          set choices to missing value

          repeat
          if choices ≠ missing value then display dialog ¬
          "You must select precisely three courses"

          set choices to choose from list theClassList with prompt ¬
          "Select three courses" with multiple selections allowed

          if choices = false or the number of choices = 3 then exit repeat
          end repeat

          if choices = false then return
          display dialog choices as text




          ...And here's a version that uses a recursive handler instead of a repeat loop:



          property theClassList : {"Math", "English", "Science", "I&S", "Design"}
          property text item delimiters : linefeed

          to choose()
          tell (choose from list theClassList ¬
          with prompt ("Select three courses") ¬
          with multiple selections allowed) to ¬
          if it = false or its length = 3 then ¬
          return it

          display dialog "You must select precisely three courses"
          choose()
          end choose

          display alert (choose() as text)





          share|improve this answer


























          • Just added a second version of the script that uses a recursive handler instead of a repeat loop. No reason why, just kinda felt like it.

            – CJK
            Jan 4 at 6:55











          • Hello, thanks for the help on this issue, however, I am confused about what the missing value means for this script, as replacing the missing value with 3 seems to also work. Thanks again

            – Kevin
            Jan 4 at 7:19











          • What made you replace it with 3 ? If you replaced both occurrences of missing value with 3, then, yes, it wouldn't affect how the script functions. You can actually replace those occurrences with any unary value and the script will still operate in an identical fashion. It's actually only there for one reason: so the dialog saying "You must select precisely three courses" doesn't get shown on the initial entry into the repeat loop. Once the loop is entered and a choice is made, that variable won't ever again equal missing value (or any unary value), so the dialog will instantiate.

            – CJK
            Jan 4 at 7:50











          • As for the choice of missing value, it's standard practice for variables that need to be initialised but don't require a specific value to be assigned a "non-value". In AppleScript, this is represented by missing value (or by null); in other languages, it's often implicit simply by declaring a variable but not assigning a value. It lets the reader know that the variable is not currently being used, but will be used later.

            – CJK
            Jan 4 at 7:54











          • This made much more sense to me. Thanks a lot for the speedy replies

            – Kevin
            Jan 4 at 7:57



















          0














          to make it easier by respecting the fluidity of your script. It would be better to declare your "theClass" as a rather string list and declare n as count of list. Below is your modified script or the following that takes your own but declaring n to count of words in "theClassString".`



          set theClassList to {"Math", "English", "Science", "I & S", "Design"}

          repeat

          set theClass to choose from list theClassList with prompt "Select three courses" with multiple selections allowed

          set theClassString to theClass as list

          set n to count of theClassString

          set n to do shell script "echo" & n

          if n ≠ "3" then

          display dialog "Please select three courses"
          exit repeat

          else if n = "3" then
          display dialog "Ok"

          end if
          end repeat


          Below
          By declaring String



          set theClassList to {"Math ", "English ", "Science ", "I&S ", "Design "}

          repeat

          set theClass to choose from list theClassList with prompt "Select three courses" with multiple selections allowed

          set theClassString to theClass as string

          set n to count of words in theClassString

          set n to do shell script "echo " & n

          if n ≠ "3" then

          display dialog "Please select three courses"
          exit repeat

          else if n = "3" then
          display dialog "Ok"

          end if
          end repeat





          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54033304%2fapplescript-using-if-then-statements-and-choose-from-list%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            It's a clever idea to count the words in the theClassString (which would be done using number of words in theClassString, instead of simply words in theClassString). This would work the majority of the time, until a user includes "I&S" as one of their options, which sadly counts as two words, "I" and "S", since the ampersand is not a word character.



            You also had your exit repeat in the wrong half of the if...then...else block, since you want to break the loop when the user selects 3 courses, not when they fail to select 3 courses.



            Rather than attempting to coerce the result of the list selection into a string, you ought to just count the number of items in the result, which can be done in one of three ways:




            1. count theClass

            2. length of theClass

            3. number in theClass


            Here's a reworked version of your script:



            property theClassList : {"Math ", "English ", "Science ", "I&S ", "Design "}
            property text item delimiters : linefeed

            set choices to missing value

            repeat
            if choices ≠ missing value then display dialog ¬
            "You must select precisely three courses"

            set choices to choose from list theClassList with prompt ¬
            "Select three courses" with multiple selections allowed

            if choices = false or the number of choices = 3 then exit repeat
            end repeat

            if choices = false then return
            display dialog choices as text




            ...And here's a version that uses a recursive handler instead of a repeat loop:



            property theClassList : {"Math", "English", "Science", "I&S", "Design"}
            property text item delimiters : linefeed

            to choose()
            tell (choose from list theClassList ¬
            with prompt ("Select three courses") ¬
            with multiple selections allowed) to ¬
            if it = false or its length = 3 then ¬
            return it

            display dialog "You must select precisely three courses"
            choose()
            end choose

            display alert (choose() as text)





            share|improve this answer


























            • Just added a second version of the script that uses a recursive handler instead of a repeat loop. No reason why, just kinda felt like it.

              – CJK
              Jan 4 at 6:55











            • Hello, thanks for the help on this issue, however, I am confused about what the missing value means for this script, as replacing the missing value with 3 seems to also work. Thanks again

              – Kevin
              Jan 4 at 7:19











            • What made you replace it with 3 ? If you replaced both occurrences of missing value with 3, then, yes, it wouldn't affect how the script functions. You can actually replace those occurrences with any unary value and the script will still operate in an identical fashion. It's actually only there for one reason: so the dialog saying "You must select precisely three courses" doesn't get shown on the initial entry into the repeat loop. Once the loop is entered and a choice is made, that variable won't ever again equal missing value (or any unary value), so the dialog will instantiate.

              – CJK
              Jan 4 at 7:50











            • As for the choice of missing value, it's standard practice for variables that need to be initialised but don't require a specific value to be assigned a "non-value". In AppleScript, this is represented by missing value (or by null); in other languages, it's often implicit simply by declaring a variable but not assigning a value. It lets the reader know that the variable is not currently being used, but will be used later.

              – CJK
              Jan 4 at 7:54











            • This made much more sense to me. Thanks a lot for the speedy replies

              – Kevin
              Jan 4 at 7:57
















            0














            It's a clever idea to count the words in the theClassString (which would be done using number of words in theClassString, instead of simply words in theClassString). This would work the majority of the time, until a user includes "I&S" as one of their options, which sadly counts as two words, "I" and "S", since the ampersand is not a word character.



            You also had your exit repeat in the wrong half of the if...then...else block, since you want to break the loop when the user selects 3 courses, not when they fail to select 3 courses.



            Rather than attempting to coerce the result of the list selection into a string, you ought to just count the number of items in the result, which can be done in one of three ways:




            1. count theClass

            2. length of theClass

            3. number in theClass


            Here's a reworked version of your script:



            property theClassList : {"Math ", "English ", "Science ", "I&S ", "Design "}
            property text item delimiters : linefeed

            set choices to missing value

            repeat
            if choices ≠ missing value then display dialog ¬
            "You must select precisely three courses"

            set choices to choose from list theClassList with prompt ¬
            "Select three courses" with multiple selections allowed

            if choices = false or the number of choices = 3 then exit repeat
            end repeat

            if choices = false then return
            display dialog choices as text




            ...And here's a version that uses a recursive handler instead of a repeat loop:



            property theClassList : {"Math", "English", "Science", "I&S", "Design"}
            property text item delimiters : linefeed

            to choose()
            tell (choose from list theClassList ¬
            with prompt ("Select three courses") ¬
            with multiple selections allowed) to ¬
            if it = false or its length = 3 then ¬
            return it

            display dialog "You must select precisely three courses"
            choose()
            end choose

            display alert (choose() as text)





            share|improve this answer


























            • Just added a second version of the script that uses a recursive handler instead of a repeat loop. No reason why, just kinda felt like it.

              – CJK
              Jan 4 at 6:55











            • Hello, thanks for the help on this issue, however, I am confused about what the missing value means for this script, as replacing the missing value with 3 seems to also work. Thanks again

              – Kevin
              Jan 4 at 7:19











            • What made you replace it with 3 ? If you replaced both occurrences of missing value with 3, then, yes, it wouldn't affect how the script functions. You can actually replace those occurrences with any unary value and the script will still operate in an identical fashion. It's actually only there for one reason: so the dialog saying "You must select precisely three courses" doesn't get shown on the initial entry into the repeat loop. Once the loop is entered and a choice is made, that variable won't ever again equal missing value (or any unary value), so the dialog will instantiate.

              – CJK
              Jan 4 at 7:50











            • As for the choice of missing value, it's standard practice for variables that need to be initialised but don't require a specific value to be assigned a "non-value". In AppleScript, this is represented by missing value (or by null); in other languages, it's often implicit simply by declaring a variable but not assigning a value. It lets the reader know that the variable is not currently being used, but will be used later.

              – CJK
              Jan 4 at 7:54











            • This made much more sense to me. Thanks a lot for the speedy replies

              – Kevin
              Jan 4 at 7:57














            0












            0








            0







            It's a clever idea to count the words in the theClassString (which would be done using number of words in theClassString, instead of simply words in theClassString). This would work the majority of the time, until a user includes "I&S" as one of their options, which sadly counts as two words, "I" and "S", since the ampersand is not a word character.



            You also had your exit repeat in the wrong half of the if...then...else block, since you want to break the loop when the user selects 3 courses, not when they fail to select 3 courses.



            Rather than attempting to coerce the result of the list selection into a string, you ought to just count the number of items in the result, which can be done in one of three ways:




            1. count theClass

            2. length of theClass

            3. number in theClass


            Here's a reworked version of your script:



            property theClassList : {"Math ", "English ", "Science ", "I&S ", "Design "}
            property text item delimiters : linefeed

            set choices to missing value

            repeat
            if choices ≠ missing value then display dialog ¬
            "You must select precisely three courses"

            set choices to choose from list theClassList with prompt ¬
            "Select three courses" with multiple selections allowed

            if choices = false or the number of choices = 3 then exit repeat
            end repeat

            if choices = false then return
            display dialog choices as text




            ...And here's a version that uses a recursive handler instead of a repeat loop:



            property theClassList : {"Math", "English", "Science", "I&S", "Design"}
            property text item delimiters : linefeed

            to choose()
            tell (choose from list theClassList ¬
            with prompt ("Select three courses") ¬
            with multiple selections allowed) to ¬
            if it = false or its length = 3 then ¬
            return it

            display dialog "You must select precisely three courses"
            choose()
            end choose

            display alert (choose() as text)





            share|improve this answer















            It's a clever idea to count the words in the theClassString (which would be done using number of words in theClassString, instead of simply words in theClassString). This would work the majority of the time, until a user includes "I&S" as one of their options, which sadly counts as two words, "I" and "S", since the ampersand is not a word character.



            You also had your exit repeat in the wrong half of the if...then...else block, since you want to break the loop when the user selects 3 courses, not when they fail to select 3 courses.



            Rather than attempting to coerce the result of the list selection into a string, you ought to just count the number of items in the result, which can be done in one of three ways:




            1. count theClass

            2. length of theClass

            3. number in theClass


            Here's a reworked version of your script:



            property theClassList : {"Math ", "English ", "Science ", "I&S ", "Design "}
            property text item delimiters : linefeed

            set choices to missing value

            repeat
            if choices ≠ missing value then display dialog ¬
            "You must select precisely three courses"

            set choices to choose from list theClassList with prompt ¬
            "Select three courses" with multiple selections allowed

            if choices = false or the number of choices = 3 then exit repeat
            end repeat

            if choices = false then return
            display dialog choices as text




            ...And here's a version that uses a recursive handler instead of a repeat loop:



            property theClassList : {"Math", "English", "Science", "I&S", "Design"}
            property text item delimiters : linefeed

            to choose()
            tell (choose from list theClassList ¬
            with prompt ("Select three courses") ¬
            with multiple selections allowed) to ¬
            if it = false or its length = 3 then ¬
            return it

            display dialog "You must select precisely three courses"
            choose()
            end choose

            display alert (choose() as text)






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 4 at 6:54

























            answered Jan 4 at 6:08









            CJKCJK

            2,6831216




            2,6831216













            • Just added a second version of the script that uses a recursive handler instead of a repeat loop. No reason why, just kinda felt like it.

              – CJK
              Jan 4 at 6:55











            • Hello, thanks for the help on this issue, however, I am confused about what the missing value means for this script, as replacing the missing value with 3 seems to also work. Thanks again

              – Kevin
              Jan 4 at 7:19











            • What made you replace it with 3 ? If you replaced both occurrences of missing value with 3, then, yes, it wouldn't affect how the script functions. You can actually replace those occurrences with any unary value and the script will still operate in an identical fashion. It's actually only there for one reason: so the dialog saying "You must select precisely three courses" doesn't get shown on the initial entry into the repeat loop. Once the loop is entered and a choice is made, that variable won't ever again equal missing value (or any unary value), so the dialog will instantiate.

              – CJK
              Jan 4 at 7:50











            • As for the choice of missing value, it's standard practice for variables that need to be initialised but don't require a specific value to be assigned a "non-value". In AppleScript, this is represented by missing value (or by null); in other languages, it's often implicit simply by declaring a variable but not assigning a value. It lets the reader know that the variable is not currently being used, but will be used later.

              – CJK
              Jan 4 at 7:54











            • This made much more sense to me. Thanks a lot for the speedy replies

              – Kevin
              Jan 4 at 7:57



















            • Just added a second version of the script that uses a recursive handler instead of a repeat loop. No reason why, just kinda felt like it.

              – CJK
              Jan 4 at 6:55











            • Hello, thanks for the help on this issue, however, I am confused about what the missing value means for this script, as replacing the missing value with 3 seems to also work. Thanks again

              – Kevin
              Jan 4 at 7:19











            • What made you replace it with 3 ? If you replaced both occurrences of missing value with 3, then, yes, it wouldn't affect how the script functions. You can actually replace those occurrences with any unary value and the script will still operate in an identical fashion. It's actually only there for one reason: so the dialog saying "You must select precisely three courses" doesn't get shown on the initial entry into the repeat loop. Once the loop is entered and a choice is made, that variable won't ever again equal missing value (or any unary value), so the dialog will instantiate.

              – CJK
              Jan 4 at 7:50











            • As for the choice of missing value, it's standard practice for variables that need to be initialised but don't require a specific value to be assigned a "non-value". In AppleScript, this is represented by missing value (or by null); in other languages, it's often implicit simply by declaring a variable but not assigning a value. It lets the reader know that the variable is not currently being used, but will be used later.

              – CJK
              Jan 4 at 7:54











            • This made much more sense to me. Thanks a lot for the speedy replies

              – Kevin
              Jan 4 at 7:57

















            Just added a second version of the script that uses a recursive handler instead of a repeat loop. No reason why, just kinda felt like it.

            – CJK
            Jan 4 at 6:55





            Just added a second version of the script that uses a recursive handler instead of a repeat loop. No reason why, just kinda felt like it.

            – CJK
            Jan 4 at 6:55













            Hello, thanks for the help on this issue, however, I am confused about what the missing value means for this script, as replacing the missing value with 3 seems to also work. Thanks again

            – Kevin
            Jan 4 at 7:19





            Hello, thanks for the help on this issue, however, I am confused about what the missing value means for this script, as replacing the missing value with 3 seems to also work. Thanks again

            – Kevin
            Jan 4 at 7:19













            What made you replace it with 3 ? If you replaced both occurrences of missing value with 3, then, yes, it wouldn't affect how the script functions. You can actually replace those occurrences with any unary value and the script will still operate in an identical fashion. It's actually only there for one reason: so the dialog saying "You must select precisely three courses" doesn't get shown on the initial entry into the repeat loop. Once the loop is entered and a choice is made, that variable won't ever again equal missing value (or any unary value), so the dialog will instantiate.

            – CJK
            Jan 4 at 7:50





            What made you replace it with 3 ? If you replaced both occurrences of missing value with 3, then, yes, it wouldn't affect how the script functions. You can actually replace those occurrences with any unary value and the script will still operate in an identical fashion. It's actually only there for one reason: so the dialog saying "You must select precisely three courses" doesn't get shown on the initial entry into the repeat loop. Once the loop is entered and a choice is made, that variable won't ever again equal missing value (or any unary value), so the dialog will instantiate.

            – CJK
            Jan 4 at 7:50













            As for the choice of missing value, it's standard practice for variables that need to be initialised but don't require a specific value to be assigned a "non-value". In AppleScript, this is represented by missing value (or by null); in other languages, it's often implicit simply by declaring a variable but not assigning a value. It lets the reader know that the variable is not currently being used, but will be used later.

            – CJK
            Jan 4 at 7:54





            As for the choice of missing value, it's standard practice for variables that need to be initialised but don't require a specific value to be assigned a "non-value". In AppleScript, this is represented by missing value (or by null); in other languages, it's often implicit simply by declaring a variable but not assigning a value. It lets the reader know that the variable is not currently being used, but will be used later.

            – CJK
            Jan 4 at 7:54













            This made much more sense to me. Thanks a lot for the speedy replies

            – Kevin
            Jan 4 at 7:57





            This made much more sense to me. Thanks a lot for the speedy replies

            – Kevin
            Jan 4 at 7:57













            0














            to make it easier by respecting the fluidity of your script. It would be better to declare your "theClass" as a rather string list and declare n as count of list. Below is your modified script or the following that takes your own but declaring n to count of words in "theClassString".`



            set theClassList to {"Math", "English", "Science", "I & S", "Design"}

            repeat

            set theClass to choose from list theClassList with prompt "Select three courses" with multiple selections allowed

            set theClassString to theClass as list

            set n to count of theClassString

            set n to do shell script "echo" & n

            if n ≠ "3" then

            display dialog "Please select three courses"
            exit repeat

            else if n = "3" then
            display dialog "Ok"

            end if
            end repeat


            Below
            By declaring String



            set theClassList to {"Math ", "English ", "Science ", "I&S ", "Design "}

            repeat

            set theClass to choose from list theClassList with prompt "Select three courses" with multiple selections allowed

            set theClassString to theClass as string

            set n to count of words in theClassString

            set n to do shell script "echo " & n

            if n ≠ "3" then

            display dialog "Please select three courses"
            exit repeat

            else if n = "3" then
            display dialog "Ok"

            end if
            end repeat





            share|improve this answer




























              0














              to make it easier by respecting the fluidity of your script. It would be better to declare your "theClass" as a rather string list and declare n as count of list. Below is your modified script or the following that takes your own but declaring n to count of words in "theClassString".`



              set theClassList to {"Math", "English", "Science", "I & S", "Design"}

              repeat

              set theClass to choose from list theClassList with prompt "Select three courses" with multiple selections allowed

              set theClassString to theClass as list

              set n to count of theClassString

              set n to do shell script "echo" & n

              if n ≠ "3" then

              display dialog "Please select three courses"
              exit repeat

              else if n = "3" then
              display dialog "Ok"

              end if
              end repeat


              Below
              By declaring String



              set theClassList to {"Math ", "English ", "Science ", "I&S ", "Design "}

              repeat

              set theClass to choose from list theClassList with prompt "Select three courses" with multiple selections allowed

              set theClassString to theClass as string

              set n to count of words in theClassString

              set n to do shell script "echo " & n

              if n ≠ "3" then

              display dialog "Please select three courses"
              exit repeat

              else if n = "3" then
              display dialog "Ok"

              end if
              end repeat





              share|improve this answer


























                0












                0








                0







                to make it easier by respecting the fluidity of your script. It would be better to declare your "theClass" as a rather string list and declare n as count of list. Below is your modified script or the following that takes your own but declaring n to count of words in "theClassString".`



                set theClassList to {"Math", "English", "Science", "I & S", "Design"}

                repeat

                set theClass to choose from list theClassList with prompt "Select three courses" with multiple selections allowed

                set theClassString to theClass as list

                set n to count of theClassString

                set n to do shell script "echo" & n

                if n ≠ "3" then

                display dialog "Please select three courses"
                exit repeat

                else if n = "3" then
                display dialog "Ok"

                end if
                end repeat


                Below
                By declaring String



                set theClassList to {"Math ", "English ", "Science ", "I&S ", "Design "}

                repeat

                set theClass to choose from list theClassList with prompt "Select three courses" with multiple selections allowed

                set theClassString to theClass as string

                set n to count of words in theClassString

                set n to do shell script "echo " & n

                if n ≠ "3" then

                display dialog "Please select three courses"
                exit repeat

                else if n = "3" then
                display dialog "Ok"

                end if
                end repeat





                share|improve this answer













                to make it easier by respecting the fluidity of your script. It would be better to declare your "theClass" as a rather string list and declare n as count of list. Below is your modified script or the following that takes your own but declaring n to count of words in "theClassString".`



                set theClassList to {"Math", "English", "Science", "I & S", "Design"}

                repeat

                set theClass to choose from list theClassList with prompt "Select three courses" with multiple selections allowed

                set theClassString to theClass as list

                set n to count of theClassString

                set n to do shell script "echo" & n

                if n ≠ "3" then

                display dialog "Please select three courses"
                exit repeat

                else if n = "3" then
                display dialog "Ok"

                end if
                end repeat


                Below
                By declaring String



                set theClassList to {"Math ", "English ", "Science ", "I&S ", "Design "}

                repeat

                set theClass to choose from list theClassList with prompt "Select three courses" with multiple selections allowed

                set theClassString to theClass as string

                set n to count of words in theClassString

                set n to do shell script "echo " & n

                if n ≠ "3" then

                display dialog "Please select three courses"
                exit repeat

                else if n = "3" then
                display dialog "Ok"

                end if
                end repeat






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 5 at 12:05









                deek5deek5

                293112




                293112






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54033304%2fapplescript-using-if-then-statements-and-choose-from-list%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas