Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the clipboard in a function

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].

like image 594
faysou Avatar asked Feb 18 '26 05:02

faysou


1 Answers

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.

like image 77
Simon Avatar answered Feb 21 '26 01:02

Simon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!