How Can I Open AppleScript App with Arguments












6














I Have an AppleScript that runs a Scan Program (commandline) that scans to a specific folder. I need to pass arguments to the applescript that in-turn passes the arguments to the terminal.



In a terminal I want to run open -a /Applications/MyScanApp.app myargument and the AppleScript runs. How can I pass that argument? Thank You for Your Help! I am normally a PHP programmer and this is something completely different to me.



My AppleScript:



tell application "Terminal"
do script "./myscanprogram myargument 2>&1"
end tell









share|improve this question





























    6














    I Have an AppleScript that runs a Scan Program (commandline) that scans to a specific folder. I need to pass arguments to the applescript that in-turn passes the arguments to the terminal.



    In a terminal I want to run open -a /Applications/MyScanApp.app myargument and the AppleScript runs. How can I pass that argument? Thank You for Your Help! I am normally a PHP programmer and this is something completely different to me.



    My AppleScript:



    tell application "Terminal"
    do script "./myscanprogram myargument 2>&1"
    end tell









    share|improve this question



























      6












      6








      6


      2





      I Have an AppleScript that runs a Scan Program (commandline) that scans to a specific folder. I need to pass arguments to the applescript that in-turn passes the arguments to the terminal.



      In a terminal I want to run open -a /Applications/MyScanApp.app myargument and the AppleScript runs. How can I pass that argument? Thank You for Your Help! I am normally a PHP programmer and this is something completely different to me.



      My AppleScript:



      tell application "Terminal"
      do script "./myscanprogram myargument 2>&1"
      end tell









      share|improve this question















      I Have an AppleScript that runs a Scan Program (commandline) that scans to a specific folder. I need to pass arguments to the applescript that in-turn passes the arguments to the terminal.



      In a terminal I want to run open -a /Applications/MyScanApp.app myargument and the AppleScript runs. How can I pass that argument? Thank You for Your Help! I am normally a PHP programmer and this is something completely different to me.



      My AppleScript:



      tell application "Terminal"
      do script "./myscanprogram myargument 2>&1"
      end tell






      bash terminal applescript






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 21 '18 at 20:42









      kenorb

      65.3k27396392




      65.3k27396392










      asked Mar 25 '15 at 14:13









      T VarcorT Varcor

      14018




      14018
























          2 Answers
          2






          active

          oldest

          votes


















          9














          Why doesn't anyone mention quoted form of? When you want to send arbitrary data as an argument to an application you should use quoted form of. When quotes, spaces and other special characters are in the given path the command will break down in de previous examples.



          on run argv
          tell application "Terminal"
          do script "./myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
          end tell
          end run


          Since you mentioned you're new to AppleScript does it have to run in the Terminal.app or is a shell enough? AppleScript has the command do shell script which opens a shell, execute the text and return the stdout back to you.



          on run argv
          do shell shell script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
          end run


          Last but not least. If you don't want the output of the scan program and don't want AppleScript to wait until it's finished you can use



          on run argv
          do script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " &>/dev/null &"
          end run





          share|improve this answer

















          • 1




            Yes, you're right. I had a strange fear of quoting the arguments twice, because you have to quote your input if it contains spaces. Otherwise the argument could be parsed as two arguments instead of one. BUT: I tested it and the savest way is the use of quoted form indeed and it works if the shell argument is already quoted, too! ;-) thumbsup
            – ShooTerKo
            Mar 27 '15 at 10:13



















          3














          Wondering why you're using your Terminal to address an AppleScript that uses the Terminal again, but maybe I just don't know your circumstances...



          Applescript:



          on run argv
          tell application "Terminal"
          do script "./myscanprogram " & (item 1 of argv) & " 2>&1"
          end tell
          end run


          Call from osascript inside your Terminal:



          osascript pathToYourScript.scpt myargument





          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%2f29258142%2fhow-can-i-open-applescript-app-with-arguments%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









            9














            Why doesn't anyone mention quoted form of? When you want to send arbitrary data as an argument to an application you should use quoted form of. When quotes, spaces and other special characters are in the given path the command will break down in de previous examples.



            on run argv
            tell application "Terminal"
            do script "./myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
            end tell
            end run


            Since you mentioned you're new to AppleScript does it have to run in the Terminal.app or is a shell enough? AppleScript has the command do shell script which opens a shell, execute the text and return the stdout back to you.



            on run argv
            do shell shell script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
            end run


            Last but not least. If you don't want the output of the scan program and don't want AppleScript to wait until it's finished you can use



            on run argv
            do script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " &>/dev/null &"
            end run





            share|improve this answer

















            • 1




              Yes, you're right. I had a strange fear of quoting the arguments twice, because you have to quote your input if it contains spaces. Otherwise the argument could be parsed as two arguments instead of one. BUT: I tested it and the savest way is the use of quoted form indeed and it works if the shell argument is already quoted, too! ;-) thumbsup
              – ShooTerKo
              Mar 27 '15 at 10:13
















            9














            Why doesn't anyone mention quoted form of? When you want to send arbitrary data as an argument to an application you should use quoted form of. When quotes, spaces and other special characters are in the given path the command will break down in de previous examples.



            on run argv
            tell application "Terminal"
            do script "./myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
            end tell
            end run


            Since you mentioned you're new to AppleScript does it have to run in the Terminal.app or is a shell enough? AppleScript has the command do shell script which opens a shell, execute the text and return the stdout back to you.



            on run argv
            do shell shell script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
            end run


            Last but not least. If you don't want the output of the scan program and don't want AppleScript to wait until it's finished you can use



            on run argv
            do script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " &>/dev/null &"
            end run





            share|improve this answer

















            • 1




              Yes, you're right. I had a strange fear of quoting the arguments twice, because you have to quote your input if it contains spaces. Otherwise the argument could be parsed as two arguments instead of one. BUT: I tested it and the savest way is the use of quoted form indeed and it works if the shell argument is already quoted, too! ;-) thumbsup
              – ShooTerKo
              Mar 27 '15 at 10:13














            9












            9








            9






            Why doesn't anyone mention quoted form of? When you want to send arbitrary data as an argument to an application you should use quoted form of. When quotes, spaces and other special characters are in the given path the command will break down in de previous examples.



            on run argv
            tell application "Terminal"
            do script "./myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
            end tell
            end run


            Since you mentioned you're new to AppleScript does it have to run in the Terminal.app or is a shell enough? AppleScript has the command do shell script which opens a shell, execute the text and return the stdout back to you.



            on run argv
            do shell shell script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
            end run


            Last but not least. If you don't want the output of the scan program and don't want AppleScript to wait until it's finished you can use



            on run argv
            do script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " &>/dev/null &"
            end run





            share|improve this answer












            Why doesn't anyone mention quoted form of? When you want to send arbitrary data as an argument to an application you should use quoted form of. When quotes, spaces and other special characters are in the given path the command will break down in de previous examples.



            on run argv
            tell application "Terminal"
            do script "./myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
            end tell
            end run


            Since you mentioned you're new to AppleScript does it have to run in the Terminal.app or is a shell enough? AppleScript has the command do shell script which opens a shell, execute the text and return the stdout back to you.



            on run argv
            do shell shell script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"
            end run


            Last but not least. If you don't want the output of the scan program and don't want AppleScript to wait until it's finished you can use



            on run argv
            do script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " &>/dev/null &"
            end run






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 25 '15 at 20:52









            dj bazzie wazziedj bazzie wazzie

            3,0421422




            3,0421422








            • 1




              Yes, you're right. I had a strange fear of quoting the arguments twice, because you have to quote your input if it contains spaces. Otherwise the argument could be parsed as two arguments instead of one. BUT: I tested it and the savest way is the use of quoted form indeed and it works if the shell argument is already quoted, too! ;-) thumbsup
              – ShooTerKo
              Mar 27 '15 at 10:13














            • 1




              Yes, you're right. I had a strange fear of quoting the arguments twice, because you have to quote your input if it contains spaces. Otherwise the argument could be parsed as two arguments instead of one. BUT: I tested it and the savest way is the use of quoted form indeed and it works if the shell argument is already quoted, too! ;-) thumbsup
              – ShooTerKo
              Mar 27 '15 at 10:13








            1




            1




            Yes, you're right. I had a strange fear of quoting the arguments twice, because you have to quote your input if it contains spaces. Otherwise the argument could be parsed as two arguments instead of one. BUT: I tested it and the savest way is the use of quoted form indeed and it works if the shell argument is already quoted, too! ;-) thumbsup
            – ShooTerKo
            Mar 27 '15 at 10:13




            Yes, you're right. I had a strange fear of quoting the arguments twice, because you have to quote your input if it contains spaces. Otherwise the argument could be parsed as two arguments instead of one. BUT: I tested it and the savest way is the use of quoted form indeed and it works if the shell argument is already quoted, too! ;-) thumbsup
            – ShooTerKo
            Mar 27 '15 at 10:13













            3














            Wondering why you're using your Terminal to address an AppleScript that uses the Terminal again, but maybe I just don't know your circumstances...



            Applescript:



            on run argv
            tell application "Terminal"
            do script "./myscanprogram " & (item 1 of argv) & " 2>&1"
            end tell
            end run


            Call from osascript inside your Terminal:



            osascript pathToYourScript.scpt myargument





            share|improve this answer




























              3














              Wondering why you're using your Terminal to address an AppleScript that uses the Terminal again, but maybe I just don't know your circumstances...



              Applescript:



              on run argv
              tell application "Terminal"
              do script "./myscanprogram " & (item 1 of argv) & " 2>&1"
              end tell
              end run


              Call from osascript inside your Terminal:



              osascript pathToYourScript.scpt myargument





              share|improve this answer


























                3












                3








                3






                Wondering why you're using your Terminal to address an AppleScript that uses the Terminal again, but maybe I just don't know your circumstances...



                Applescript:



                on run argv
                tell application "Terminal"
                do script "./myscanprogram " & (item 1 of argv) & " 2>&1"
                end tell
                end run


                Call from osascript inside your Terminal:



                osascript pathToYourScript.scpt myargument





                share|improve this answer














                Wondering why you're using your Terminal to address an AppleScript that uses the Terminal again, but maybe I just don't know your circumstances...



                Applescript:



                on run argv
                tell application "Terminal"
                do script "./myscanprogram " & (item 1 of argv) & " 2>&1"
                end tell
                end run


                Call from osascript inside your Terminal:



                osascript pathToYourScript.scpt myargument






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 12 '18 at 20:08









                Utku

                849827




                849827










                answered Mar 25 '15 at 15:45









                ShooTerKoShooTerKo

                1,7441815




                1,7441815






























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f29258142%2fhow-can-i-open-applescript-app-with-arguments%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

                    Florida Star v. B. J. F.

                    Danny Elfman

                    Lugert, Oklahoma