4
$\begingroup$

Consider the following example:

CopyToClipboard["1\t2"];
Button["Paste", FrontEndTokenExecute["Paste"]]
CellPrint @ Cell[BoxData @ ToBoxes[""], "Input"]

Now move your cursor between the quote characters in the newly printed cell and press the button. You'll get this choice dialog asking you how to paste the characters:

enter image description here

Is there a way to programmatically disable this dialog and just pick a default paste? It doesn't even really matter to me which type of paste it uses; I just don't want the message to show up and hold up evaluation.

Edit

To clarify: the string on the clipboard could be anything; I just picked this one as an easy example to illustrate the problem. Assume you have no control over what's on the clipboard.

$\endgroup$
6
  • $\begingroup$ Does using CopyToClipboard["\"" <> "1\t2" <> "\""]; Button["Paste", FrontEndTokenExecute["Paste"]] instead solve your problem? I mean copy to clipboard with \" on both ends of the string and then pasting on a plain cell instead in between "". $\endgroup$ Commented Nov 10, 2022 at 12:07
  • $\begingroup$ @azerbajdzan The string copied to the clipboard is there to illustrate the problem; you should assume that this string can come from anywhere and you don't have control over it. $\endgroup$ Commented Nov 10, 2022 at 12:12
  • $\begingroup$ You might have no control over what is on the clipboard but if you have control over pasting then you can always prepend and append "\"" to the string from the clipboard and only then pasting. $\endgroup$ Commented Nov 10, 2022 at 12:18
  • 2
    $\begingroup$ This prompt cannot be suppressed by the user. $\endgroup$
    – ihojnicki
    Commented Nov 10, 2022 at 13:18
  • 1
    $\begingroup$ If "Raw InputForm" works for you, something like CellPrint@Cell["","Input"] could be used so it completely avoids dealing with boxes (at this stage). $\endgroup$
    – Silvia
    Commented Nov 10, 2022 at 16:20

1 Answer 1

3
$\begingroup$

Although the popup can not be suppressed by users (according to ihojnicki), the situation could be completely avoided by using CellPrint @ Cell["", "Input"] instead as a workaround, so the generated cell is in "Raw InputForm" mode, skipping anything about parsing and boxes.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.