void () { 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); } }); }