MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Accessing the contents of the clipboard

Is there a *reliable* way to get the text that was copied to the

First I experimented with creating a hidden notebook and pasting to
it, like this:

nb = CreateDocument[Null, Visible -> False];
FrontEndExecute@FrontEndToken[nb, "PasteSpecial"]

NotebookGet[nb] (* extract the data somehow ... *)


The problem is that I would like to access the exact string that was
copied, but NotebookGet returns a complicated BoxData structure that
may contain many things, even when the clipboard only had plain text
on it.  I do not know how to convert it back to the *same* string that
was copied, because in edge cases Mathematica might have interpreted
the text ... what if the text was "\(k\_1\)"? (Unlikely, I know, but I
would like to avoid unpleasant surprises.)

Then, in final desperation, I turned to the JLink documentation, and
using this page I put together something:

But I would like to avoid using JLink very much, because I do NOT know
Java (this is the first Java program I have ever written, if it can be
counted as a Java program at all ...), and I do not know what are the
things that can go wrong ...

So I am looking for better, preferably "pure Mathematica" suggestions.

<< JLink`



dtk = Toolkit`getDefaultToolkit[]

clipboard = dtk@getSystemClipboard[]

clipdata = clipboard@getContents[clipboard]


  • Prev by Date: MathLink with MS Visual Studio 2008
  • Next by Date: Re: Accessing the contents of the clipboard
  • Previous by thread: Re: MathLink with MS Visual Studio 2008
  • Next by thread: Re: Accessing the contents of the clipboard