When I actually launch the appium server and run the code, finder opens the java application and code exits with no error. The home button isn’t simulated either. Any thoughts on this?
Robot robot = new Robot();
robot.setAutoDelay(300);
// Use Apple script to get focus on the simulator
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("AppleScript");
String script = "tell application \"Simulator\" \n activate \n end tell";
engine.eval(script);
robot.keyPress(KeyEvent.VK_META);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_H);
// Have to release the key press
robot.keyRelease(KeyEvent.VK_H);
robot.keyRelease(KeyEvent.VK_H);
robot.keyRelease(KeyEvent.VK_SHIFT);
There are 2 things you need to be aware of here:
You have to get focus on the simulator before you press on the combination of SHIFT + OPTION + H. Otherwise robot java program ( which is launched separately) will get the focus