3

How can I use the content of the clipboard in a function?

When I use Paste[] it copies it in the current cell of the active notebook. On the other hand, I can easily put an expression to the clipboard using CopyToClipboard[expr].

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
faysou
  • 1,142
  • 11
  • 25

1 Answers1

6

You could try using ClipboardNotebook[]

In[1]:= CopyToClipboard[expression]

In[2]:= an[ToExpression[NotebookGet[ClipboardNotebook[]][[1, 1, 1]]]]

Out[2]= an[expression]

Although you should probably be more careful with it than I have been in the above code. See for example Szabolcs' Mathematica tricks.

Community
  • 1
  • 1
Simon
  • 14,631
  • 4
  • 41
  • 101
  • Beat me to it by half a minute :-) I believe you don't actually need `ToExpression` here, it might only cause an error. – Szabolcs Dec 15 '11 at 10:27
  • @Szabolcs: It was close! In this case, I agree, you don't need the `ToExpression`. But in more general cases, I thought the box structures needed to be translated. Especially if the clipboard contents come from `CopyToClipboard[expr]` – Simon Dec 15 '11 at 10:53