Running the demo code below pops up a dialog window with an InputField
that returns a String
. The combined effect of the two SelectionMove
commands is to put the focus inside the InputField
. The While
step spin-waits until an acceptable input has been entered. After that normal execution proceeds.
Module[{nb},
Clear[newName];
nb =
CreateDialog[
Column[{TextCell["Enter new name", 20],
Row[{InputField[Dynamic[newName], String, Alignment -> Right]},
BaseStyle -> 16, Alignment -> Center],
DefaultButton[DialogReturn[]]}, Alignment -> Center],
Modal -> True(* Block other Mathematica windows until closed. *)
];
(* Move window focus to input field, then wait until new name has been entered. *)
SelectionMove[nb, Before, CellContents];
SelectionMove[nb, Next, TextLine];
While[Not[StringQ[newName]]]
];
Print["Proceed with newName = ", newName]
Tested in Mathematica v12.xx and v13.xx