7
$\begingroup$

If I copy something into the clipboard then use var=Paste[]; I get Null in the var and the clipboard content is printed on the next cell. How do I get the content of the clipboard directly into the variable.

I have a basic text in my clipboard and want it stored as a string.

Moreover Windows 10's clipboard now supports multiple entries. Is there a way to select entries other than the last one?

$\endgroup$
0
8
$\begingroup$

To get the last entry in clipboard you can use:

var = ToExpression[NotebookGet[ClipboardNotebook[]][[1, 1, 1, 1]]]

This works in version 9 / windows 10 (64bit).

$\endgroup$
2
  • $\begingroup$ This allows to get only the last entry from the clipboard on Windows 10. $\endgroup$ Oct 24 '21 at 4:04
  • $\begingroup$ Good point, thank you @AlexeyPopkov. $\endgroup$
    – kglr
    Oct 24 '21 at 19:33
0
$\begingroup$

This is perhaps a partial answer; it shows that using ctrl+v rather than Paste[] allows an expression to be assigned to a variable as required.

As an example, enter

Red[]

Shows red box.

Select the box then use Paste from the context menu to copy it to the clip-board; then enter

x = Paste[]
x // FullForm

This shows x = Null.

Next, enter

y=

then type ctrl+v

This gives the red box as expected; enter

y // FullForm

This gives RGBColor[1,0,0], which shows that the expressions has been passed to y as required.

$\endgroup$
-1
$\begingroup$

Actually, there is an undocumented function for this purpose:PastContent[]

$\endgroup$
3
  • $\begingroup$ There is no built-in function PastContent, at least in version 12.3.1: Names["*`*Past*Content*"] returns empty list. Probably you refer to this: mmaqa.com/qa/1731/mmaexcelmma?show=1773#a1773 $\endgroup$ Oct 24 '21 at 3:59
  • $\begingroup$ @AlexeyPopkov Aha..Life is hard, and I don't remember what I ever did at all. That link you quoted is exactly one of the questions I answered myself a few years ago. BTW, you're Chinese? How did you find out about that community? $\endgroup$
    – yode
    Oct 24 '21 at 11:37
  • $\begingroup$ No, I've found this link here. $\endgroup$ Oct 24 '21 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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