Re: Easy way to read clipboard?
- To: mathgroup at smc.vnet.net
- Subject: [mg117874] Re: Easy way to read clipboard?
- From: David Bailey <dave at removedbailey.co.uk>
- Date: Sat, 2 Apr 2011 02:43:15 -0500 (EST)
- References: <in3v6n$i0i$1@smc.vnet.net>
On 01/04/2011 08:34, mmausr wrote: > The Paste[] command will paste the current contents of the clipboard > into a cell. In theory, one can then access the contents of a cell by > executing front-end commands in the kernel, but I'd prefer something > more direct. > > Say that I want to set the variable Foo to the current contents of the > Clipboard, which holds the number 100. I'd like to be able to execute > something like Foo = ReadClipboard[] and have Foo set to the integer > value 100. > > Any suggestions? > > > You can obtain the clipboard in the form of a notebook expression: NotebookGet[ClipboardNotebook[]] This is a bit messy however, because in general, the contents of the clipboard under Mathematica, may contain several cells, including text cells, and formatting information. If you knew that the clipboard should only contain a certain type of thing - say a number, or an expression, you could write code to extract it from the notebook expression, but to make it robust, you would have to decide what to do with all the other things that might be in the clipboard - such as: foo[ David Bailey http://www.dbaileyconsultancy.co.uk