Shop OBEX P1 Docs P2 Docs Learn Events
Scripting PNUT — Parallax Forums

Scripting PNUT

I have been trying to figure this out for a while. Turns out, I didn't know how to run a JavaScript. (In Windows) files of type .js are executable...who would have thunk it?:)

This allows us to tell PNUT to compile a specific file, automatically save it, then load the P2 and quit PNUT. This is useful when working on the compute side of the equation (for me this means working on P2Explorer).
(function () {
          var WshShell = WScript.CreateObject("WScript.Shell");
          WshShell.Run ("C:/Users/Public/p2/PNut_v7.exe C:/Users/Public/p2/P2host1x.spin", 9);
          WScript.Sleep(1500); 
          WshShell.SendKeys("^{b}");
          var msg = " 'Hello, World!";
          // Give PNUT time to load
          WScript.Sleep(500); 
          for (i = 0; i < msg.length; i ++) {
              WScript.Sleep(200);
              WshShell.SendKeys(msg.charAt(i));
          }
        
          // Alt + F4
          WshShell.SendKeys("{ENTER}");
          WshShell.SendKeys("{F11}");
          //compile and run
         
          WScript.Sleep(200);
          WScript.Sleep(2000);
          WshShell.SendKeys("%{F4}");
     
          // Exit
               
})(); 


There all kinds of warnings not to do this sort of thing. For instance, if your computer is busy and takes too much time to start PNUT, your JavaScript instructions don't go to PNUT and then all kinds of fun things happen:) It is like driving a car, without being able to see.
But used judiciously... who cares?

Sign In or Register to comment.