void () { myLog.setText(null); addInfo("Waiting for IDE frame activation", -1, MESSAGE_COLOR, 0); runner = new PlaybackRunner(myCodeEditor.getText(), this, false, true, false); VirtualFile file = pathToFile(); if (file != null) { VirtualFile scriptDir = file.getParent(); if (scriptDir != null) { runner.setScriptDir(new File(scriptDir.getPresentableUrl())); } } new Thread("playback debugger") { @Override public void run() { new WaitFor(60000) { @Override protected boolean condition() { return KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow() instanceof IdeFrame || runner == null; } }; if (runner == null) { message(null, "Script stopped", -1, Type.message, true); return; } message(null, "Starting script...", -1, Type.message, true); TimeoutUtil.sleep(1000); if (runner == null) { message(null, "Script stopped", -1, Type.message, true); return; } PlaybackRunner runner = PlaybackDebugger.this.runner; PlaybackDebugger.this.runner.run().whenComplete((o, throwable) -> { if (runner == PlaybackDebugger.this.runner) { SwingUtilities.invokeLater(() -> PlaybackDebugger.this.runner = null); } }); } }.start(); }