Promise<Object> (final @NotNull PlaybackContext context) { final String actionName = getText().substring(PREFIX.length()).trim(); final ActionManager am = ActionManager.getInstance(); final AnAction targetAction = am.getAction(actionName); if (targetAction == null) { dumpError(context, "Unknown action: " + actionName); return Promises.rejectedPromise(); } if (!context.isUseDirectActionCall()) { final Shortcut[] sc = getActiveKeymapShortcuts(actionName).getShortcuts(); KeyStroke stroke = null; for (Shortcut each : sc) { if (each instanceof KeyboardShortcut ks) { final KeyStroke first = ks.getFirstKeyStroke(); final KeyStroke second = ks.getSecondKeyStroke(); if (second == null) { stroke = KeyStroke.getKeyStroke(first.getKeyCode(), first.getModifiers(), false); break; } } } if (stroke != null) { final ActionCallback result = new TimedOutCallback(Registry.intValue("actionSystem.commandProcessingTimeout"), "Timed out calling action id=" + actionName, new Throwable(), true) { @Override protected void dumpError() { context.error(getMessage(), getLine()); } }; context.message("Invoking action via shortcut: " + stroke, getLine()); final KeyStroke finalStroke = stroke; inWriteSafeContext(() -> { Disposable disposable = Disposer.newDisposable(); ApplicationManager.getApplication().getMessageBus().connect(disposable).subscribe(AnActionListener.TOPIC, new AnActionListener() { @Override public void beforeActionPerformed(@NotNull AnAction action, @NotNull AnActionEvent event) { ApplicationManager.getApplication().invokeLater(() -> { if (context.isDisposed()) { Disposer.dispose(disposable); return; } if (targetAction.equals(action)) { context.message("Performed action: " + actionName, context.getCurrentLine()); Disposer.dispose(disposable); result.setDone(); } }, ModalityState.any()); } }); context.runPooledThread(() -> type(context.getRobot(), finalStroke)); }); return Promises.toPromise(result); } } final InputEvent input = getInputEvent(actionName); final ActionCallback result = new ActionCallback(); context.getRobot().delay(Registry.intValue("actionSystem.playback.delay")); ApplicationManager.getApplication().invokeLater( () -> am.tryToExecute(targetAction, input, null, null, false).doWhenProcessed(result.createSetDoneRunnable()), ModalityState.any()); return Promises.toPromise(result); }