You can't run Kernel Blocking Dialogs on the preemptive link. But you can prompt other dialogs. And we can abuse that to run a procedure containing Input[]
, DialogInput[]
or some system dialogs.
The trick is to run your code inside an asynchronous initialization of the regular dialog:
MessageDialog[
DynamicModule[{},
1,
Initialization :> (
NotebookClose @ EvaluationNotebook[];
(*put here a custom procedure*)
),
SynchronousInitialization -> False
],
Visible -> False
]
This regular invisible dialog is closed automatically by itself.
We can test it with Button
as by default it uses preemptive link, just like procedures assigned to keyboard shortcuts.
Normally you wouldn't be able to run this procedure from there:
procedure[] := Module[{test}, test = Input[]; Print[test]];
Button["test", procedure[]]
Input::nprmtv: Input is not currently supported within preemptive evaluations. >> (after click)
But with this workaround it works:
Button["test",
MessageDialog[
DynamicModule[{}, 1,
Initialization :> (NotebookClose@EvaluationNotebook[];
procedure[]), SynchronousInitialization -> False],
Visible -> False]
]
MessageDialog
first and from there run whatever you want. $\endgroup$