cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Mac/Linux trigger Java GUI Scripting from command line

0 Likes
2,969

Scenario

I am able to trigger a javascript file from command line like this:

test1.js

application.openConnectionByConnectionString("conn=/H/10.10.10.100/S/3200&expert=true");
application.findById("/app/con[0]/ses[0]/wnd[0]/usr/txtRSYST-MANDT").text = "220";
application.findById("/app/con[0]/ses[0]/wnd[0]/usr/txtRSYST-MANDT").setFocus();
application.findById("/app/con[0]/ses[0]/wnd[0]/usr/txtRSYST-MANDT").caretPosition = 3;
application.findById("/app/con[0]/ses[0]/wnd[0]/usr/txtRSYST-BNAME").text = "username";
// The text of a password field is not recorded. Either enter a valid password or delete the following line
application.findById("/app/con[0]/ses[0]/wnd[0]/usr/pwdRSYST-BCODE").text = "secret";
application.findById("/app/con[0]/ses[0]/wnd[0]").resizeWorkingPane(181,35,false);
application.findById("/app/con[0]/ses[0]/wnd[0]").sendVKey(0);
application.findById("/app/con[0]/ses[0]/wnd[0]/tbar[0]/okcd").text = "/nex";
application.findById("/app/con[0]/ses[0]/wnd[0]").sendVKey(0);
#!/bin/bash
export SAPGUIDIR="/Applications/SAP Clients/SAPGUI 7.50rev5/SAPGUI 7.50rev5.app/Contents/Resources"
export WORKDIR=`pwd` # this is where the script file is located

cd "${SAPGUIDIR}"
echo "[DEBUG] starting..."

java \
	-cp Java/GuiStartS.jar com.sap.platin.Gui \
	-n \
	-b \
	-f ${WORKDIR}/test1.js

echo "[DEBUG] done!"

Problem
JavaGUI does not quit. There is a popup that says "The script has successfully completed its execution".

If I run the command again, I get another copy of JavaGUI running ...

How can I get JavaGUI to quit completely?

Please could anyone share a link to the full JavaScript API?

View Entire Topic
raniemi
Newcomer
0 Likes

In case someone comes across this thread and that they're having issues with SAPGUI for Java 7.80:

  • The NOPHANTOM trace appears to be replaced with SCRIPTNOMESSAGE
    • The reason why this works is because setting this trace (as a side effect) puts SAPGUI into "unattended mode"
  • If you rather not use SCRIPTNOMESSAGE (and see unnecessary tracing) then at the beginning of your script you can do the following (undocumented) trick:
    • application.unwrap(application).mUnattended = true;
  • I know there are references in this thread about how the SAPGUI can/will exit after the script completes and elsewhere in the SAPGUI documentation it suggests that closing connections/sessions should shutdown the SAPGUI -- but this has not been my experience. 
    • After closing the connections/sessions and confirming it completed with the SHUTDOWN trace, at the end of my script I now call:
      • java.lang.System.exit(0);
    • NOTE: This will not work with the Java Security policy that is shipped with the SAPGUI.  I had to call the SAPGUI using Java (like the author originally did) and pass in the absolute path for a custom security policy to the JVM at start up:
      • java -Djava.security.policy=file://...
    • The contents of the security policy I used are:
      • grant principal com.sap.platin.micro.GuiPrincipal "SAPGUI:UserScript" {
            permission java.io.FilePermission "<<ALL FILES>>", "read,write,delete,execute";
            permission java.lang.RuntimePermission "getenv.*";
            // Generic Permissions necessary for Scripting
            permission javax.security.auth.AuthPermission "doAsPrivileged";
            permission java.awt.AWTPermission "createRobot";
         
            // Allow the script to exit
            permission java.lang.RuntimePermission "exitVM";
        };