Re: Funny behaviour of ClipboardNotebook[] (Q: How to copy programmatically?)
- To: mathgroup at smc.vnet.net
- Subject: [mg86898] Re: [mg86839] Funny behaviour of ClipboardNotebook[] (Q: How to copy programmatically?)
- From: "Szabolcs HorvÃt" <szhorvat at gmail.com>
- Date: Wed, 26 Mar 2008 04:47:04 -0500 (EST)
- References: <200803230601.BAA25755@smc.vnet.net>
Thank you for the reply! This solution works well.
On Mon, Mar 24, 2008 at 10:12 PM, John Fultz <jfultz at wolfram.com> wrote:
> The proper structure of Notebook[] is Notebook[{cell1, cell2, etc.}, opts].
> This is documented in the documentation for Notebook[].
Actually the documentation for Notebook[] only contains an example,
but it is not clear that this is the /only/ acceptable syntax, so it
is natural that one starts experimenting. I tried to achieve an
effect similar to simply copying plain text from Notepad, i.e. I did
not want any style information to be associated with the copied text.
I was not sure what style to use with Notebook[{Cell["abc",
"style"]}], so I tried Notebook[{"abc"}] which appeared to work.
(Most probably the style should be "Input".)
>
> However, your method of writing to the clipboard isn't going to work robustly.
> You can read the values off the clipboard notebook pretty robustly, but writing
> to the clipboard notebook doesn't always interact with the clipboard as you
> would expect.
>
> The most robust way of copying something to the clipboard is to create a
> temporary, invisible notebook with what you want and execute the "Copy" front
> end token. This method can also allow you to sidestep the issue of creating
> correct cells. E.g.,
>
> nb = NotebookCreate[Visible -> False];
> NotebookWrite[nb, "2+2"];
> SelectionMove[nb, All, Notebook];
> FrontEndTokenExecute[nb, "Copy"];
> NotebookClose[nb];
How would one use CreateDocument[] instead of NotebookCreate[] and
NotebookWrite[]? (According to the documentation, NotebookCreate[] is
obsolete, and CreateDocument[] can insert an expression into the
notebook right after it is created.)
Is the following correct and equivalent to nb = NotebookCreate[];
NotebookWrite[nb, "2+2"] ?
nb = CreateDocument[Cell[BoxData["2+2"], "Input"]];
>
> There are a few places where Mathematica itself uses this technique to
> programmatically deliver something to the clipboard. We're working on a design
> for a much easier way to do this in future versions.
>
> Sincerely,
>
> John Fultz
> jfultz at wolfram.com
> User Interface Group
> Wolfram Research, Inc.
>
>
>
>
> On Sun, 23 Mar 2008 01:01:12 -0500 (EST), Szabolcs Horvát wrote:
> >
> >
> > When pasting quoted text from an e-mail, Mathematica will offer to
> > remove the quoting marks. It says:
> >
> > "The text you are pasting appears to be from a quoted email. Do you
> > want Mathematica to remove the quoting marks before pasting it?" (Yes|No)
> >
> > Here is a quoted expression to try this:
> >
> >> {9,
> >> 0,
> >> 7,
> >> 8,
> >> 7,
> >> 2,
> >> 5,
> >> 0,
> >> 7,
> >> 1}
> >>
> > The dialogue box also comes up when evaluating the following to access
> > the clipboard programmatically:
> >
> > NotebookGet@ClipboardNotebook[]
> >
> > This is expected and understandable. But the dialogue box appears when
> > using NotebookPut[] too if the clipboard contains a quoted expression!
> >
> > NotebookPut[Notebook[{"abc"}], ClipboardNotebook[]]
> >
> > Why does this happen? Is it a bug? Also, is this the correct way to
> > *copy* a string to the clipboard programmatically? It does work, but I
> > am not sure if Notebook[{"abc"}] (with no Cells) is a correct Notebook
> > expression. (Where is the correct syntax documented?)
>
>
>
- References:
- Funny behaviour of ClipboardNotebook[] (Q: How to copy programmatically?)
- From: Szabolcs Horvát <szhorvat@gmail.com>
- Funny behaviour of ClipboardNotebook[] (Q: How to copy programmatically?)