6 Replies Latest reply on Apr 30, 2014 9:16 AM by Trevorׅ

    How to get the response of a vbscript ran from extended js?

    Shadowfax Level 1

      Hi All,

       

      I  want to get the result from a vbscript, how to get that in my jsx? This is what I'm doing-

       

       

      vbscript (this will return me something, i've added just a sample string)

       

      Wscript.Echo "Like this?"
      

       

       

      jsx

       

       var a = File("C:\\Users\\Sahil\\AppData\\Roaming\\CreativeWorx\\1.vbs");
       var b=a.execute();
      
      

       

      Now, variable b returns me true/false; and the output i.e. "Like this?"  is alerted! So my question is-

       

      1. How to get the output in a variable?

      2. How to avoid the alert

       

      So, I simply wish to get the output from my vbscript and then perform certain functions accordingly, alos, I dont want  this to be alerted!

       

       

      Any help will be highly appreciated!

        • 1. Re: How to get the response of a vbscript ran from extended js?
          Trevorׅ Adobe Community Professional

          Hi Shadow fax,

           

          Use scriptArgs and doScript

           

          var VBScript = 'app.scriptArgs.SetValue "myResult", "Like This"';
          app.doScript(VBScript, ScriptLanguage.visualBasic);
          alert(app.scriptArgs.getValue("myResult"));
          

           

          Trevor

           

          Message was edited by: Trevorׅ P.s. I didn't read what you read about the alert stuff but HTH anyway

          • 2. Re: How to get the response of a vbscript ran from extended js?
            Shadowfax Level 1

            @Travor, thanks for your reply

             

            I forgot to mention in the question but, this script is for Windows. And I guess, doscript is for Macintosh right?

             

            If I'm right, how could I get the output of vbscript back in my extendscript?

            • 3. Re: How to get the response of a vbscript ran from extended js?
              Trevorׅ Adobe Community Professional

              Wrong, doScript is for both Mac and Windows

              So it should work for you

              Give it a go

              • 4. Re: How to get the response of a vbscript ran from extended js?
                Shadowfax Level 1

                @Trevor, Thanks again, but it says method not found "app.doScript"

                 

                Another thing- my vbscript actually returns the network's mac address, so your method will work with this right?

                 

                This will be my vbscript-

                 

                dim WMI:  set WMI = GetObject("winmgmts:\\.\root\cimv2")
                dim Nads: set Nads = WMI.ExecQuery("Select * from Win32_NetworkAdapter where physicaladapter=true")
                dim nad
                for each Nad in Nads
                   
                if not isnull(Nad.MACAddress) then Wscript.Echo Nad.description, Nad.MACAddress  
                next

                • 5. Re: How to get the response of a vbscript ran from extended js?
                  Trevorׅ Adobe Community Professional

                  The capitalization is app.doScript and not app.doscript that is if you are trying to get a jsx script to run and access a string from from a vbs script.

                   

                  When defining the VBscript for multiline scripts the easiest method is to use triple quotes

                   

                  VBscript = """dim WMI:  set WMI = GetObject("winmgmts:\\.\root\cimv2")
                  dim Nads: set Nads = WMI.ExecQuery("Select * from Win32_NetworkAdapter where physicaladapter=true") 
                  dim nad
                  for each Nad in Nads
                      if not isnull(Nad.MACAddress) then Wscript.Echo Nad.description, Nad.MACAddress   
                  next"""
                  

                   

                  when using the scriptArgs you can either make a loop of them and send the string value of each one something like this

                  For (n = 0 .........

                  myArg = "myArg" & n

                  myStringToPassOver = "Shaddow Fax " & n

                  app.scriptArgs.SetValue myArg, myStringToPassOver

                  Next

                  .........

                   

                  or probably better to make a long comma or something else separated string and pass it over after the loop

                   

                  var VBScript = """myArg = ""
                  For n = 0 To 15
                  myArg = myArg & "Shaddow Fax " & n & ","
                  Next
                  app.scriptArgs.SetValue "myResult", myArg
                  """;
                  app.doScript(VBScript, ScriptLanguage.visualBasic);
                  var myResult = app.scriptArgs.getValue("myResult").replace(/\,$/,"").split(","); 
                  // if neaded use "replace" to remove final "," and "split" to convert into an array
                  alert(myResult.join("\r")); // alert the array
                  

                   

                  The above script is a jsx script that runs a vbs

                   

                  If you want a vbs script to run and access a string from from a jsx script then you would use xxx.DoScript see the sample from the manual below.

                   

                  Set myInDesign = CreateObject("InDesign.Application")
                  myJavaScript = "alert(""First argument: "" + arguments[0] + ""\rSecond argument: "" +
                  arguments[1]);"
                  myInDesign.DoScript myJavaScript, idScriptLanguage.idJavascript, Array("Hello from
                  DoScript", "Your message here.")
                  myVBScript = "msgbox arguments(1), vbOKOnly, ""First argument: "" & arguments(0)"
                  myInDesign.DoScript myVBScript, idScriptLanguage.idVisualBasic, Array("Hello from
                  DoScript", "Your message here.")
                  

                   

                   

                  P.s.Please mark the question as answered, thanks

                  • 6. Re: How to get the response of a vbscript ran from extended js?
                    Trevorׅ Adobe Community Professional

                    P.s.

                     

                    Although I quite possibly make it into the worlds top 2 billion vb programmers I can't help you with your specific script which is trying to get the network mac address.