Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

There is of course function

Notebooks[]

enter image description here

But, unfortunatelly it hasn't got useful options in this context.

My question is how to pick Notebooks excluding:

  • Help,
  • Palettes,
  • Packages,
  • Messages,
  • Text notebooks.

Parsing Notebook/CellInformation functions, I've found Patterns, e.g.:

ClearAttributes[Developer`CellInformation, ReadProtected]
DownValues @ Developer`CellInformation
[...]  (_FrontEnd`SelectedNotebook | _FrontEnd`InputNotebook | 
 _FrontEnd`ButtonNotebook | _FrontEnd`EvaluationNotebook | 
 _FrontEnd`MessagesNotebook | _FrontEnd`HelpBrowserNotebook | 
 _FrontEnd`ClipboardNotebook) | (_CellObject | _FrontEnd`CellObject) [...]

Those patterns seem to be what I need but I've not managed to use them. Any tips or another solution?

share|improve this question

4 Answers 4

up vote 6 down vote accepted

I think the information given by AbsoluteOptions will be enough to distinguish one type of Notebook from another.

To investigate the differences among the option values of different Notebooks, we first prepare all six types of Notebooks:

nblist = Complement[Notebooks[], {EvaluationNotebook[]}]

test notebooks

Then we extract all of their AbsoluteOptions, and delete those which are the same among different types of Notebooks.

Then we count the (rescaled) commonness of the option values. e.g. Option CellLabelAutoDelete has value True for Message, Package, Text, Palette and ordinary Notebook, but False for Help windows, so the commonness of CellLabelAutoDelete for Message, Package, Text, Palette, ordinary Notebook and Help will be MapAt[Rescale, Tally[{True, True, True, True, True, False}]\[Transpose], 2]\[Transpose], which is {{True, 1}, {False, 0}}. i.e. the more common the value of an option is, the more the commonness of the option approaches 1. By counting the commonness, we can identify the most unique options a Notebook type has.

nboptSet = AbsoluteOptions /@ nblist;
nbopts = nboptSet // Flatten // #[[All, 1]] & // Union;
optdataRules = DeleteCases[
      {#, MapAt[Rescale, Tally[# /. nboptSet]\[Transpose], 2]\[Transpose]} & /@ nbopts,
      {_, {{__}}}, 1]\[Transpose] //
    MapAt[Map[Rule @@ # &, #, {2}] &, #, 2] & //
   SortBy[#, First] &;

At last we plot out the chart:

MapThread[#1 /. #2 &, {optdataRules[[1]] /. #, optdataRules[[2]]}] & /@ nboptSet //
    Map[Item["", Background -> GrayLevel[# + .8]] &, #, {2}] & //
   Prepend[#, optdataRules[[1]]] & //
  Prepend[#\[Transpose], {"", "Msg", "Pkg", "Txt", "Plt", "ONb", "Hlp"}] & //
 Grid[#, Frame -> All, Alignment -> Left, FrameStyle -> GrayLevel[.7]] &

commonness statistics

Now it's clear to see that CellInsertionPointCell is (one of) the perfect "fingerprint" of ordinary Notebook-s. So the filter function is simple:

Pick[#,
   (CellInsertionPointCell /. AbsoluteOptions[#, CellInsertionPointCell]) =!= None & /@ #
   ] & @ Notebooks[]

ordnb filter result

share|improve this answer
    
You've done what I was too lazy (ashamed) to do. Thank you :) –  Kuba Mar 28 at 20:31
    
@Kuba You're welcome:) I think I spent too much time on trying different color schemes for the Grid O_o –  Silvia Mar 28 at 20:33
1  
It is standard for me that I'm wasting 80% time for secondary quests while playing with mma :) –  Kuba Mar 28 at 20:39
    
@Kuba I'm hoping someone will give a machine learning and classification answer :D –  Silvia Mar 28 at 20:45
    
Oh my, there will be so many things to test. :) –  Kuba Mar 28 at 20:49

I don't know any neat answer but here's one that works for me at the moment.

  • How we can detect Help, Text, Package type notebooks:

    "DocumentType" /. NotebookInformation /@ Notebooks[]
    
    {"Notebook", "Notebook", "Notebook", "Help", "Package", "Text", "Notebook",
    "Notebook", "Notebook", "Notebook"}
    
  • Message is the only one with no external "StyleDefinitions":

    {#, "StyleDefinitions" /. NotebookInformation[#]} & /@ Notebooks[]
    

    enter image description here

    In fact this method could help further, but people often change things in styles so I do not trust it. Let's:

  • ... find Palettes using FrontEndTokens (list of tokens), with a support of answer on MathGroup by John Fultz:

    FE`Evaluate[FEPrivate`GetPopupList["MenuListPaletteWindows"]]
    

So at the end I'm using:

Composition[
 Complement[#, FE`Evaluate[FEPrivate`GetPopupList["MenuListPaletteWindows"]][[;;,1]]] &,
 DeleteCases[#, {_, {"Text" | "Help" | "Package", _}} | {_, {_, None}}, 1][[;; , 1]] &,
 Map[{#, {"DocumentType", "StyleDefinitions"} /. NotebookInformation[#]} &, #] &
  ][Notebooks[]]

But it is soo ugly :(

share|improve this answer
    
+1. btw instead of NotebookInformation, it might be worth trying AbsoluteOptions on every nb, I believe the information will be more than enough to distinguish one from another. –  Silvia Mar 28 at 16:41
    
@Silvia You are probably right, but there is to much to scan :) so I've taken easier but longer road –  Kuba Mar 28 at 16:51
    
The scan can be done automatically. (well at least they appear to be if we ignore all the coding time!) Please see my answer for detail :) –  Silvia Mar 28 at 20:26

Palettes have a specific window frame, so:

DeleteCases[Notebooks[], x_ /; MemberQ[Options[x], WindowFrame -> "Palette"]]

The Help seems to have a specific docked cell, so:

DeleteCases[Notebooks[], 
 x_ /; MemberQ[Options[x], DockedCells -> 
 FEPrivate`FrontEndResource["FEExpressions", "HelpViewerToolbar"]]]

So you can combine these two:

DeleteCases[Notebooks[], 
 x_ /; MemberQ[Options[x], 
   HoldPattern[_ -> 
     FEPrivate`FrontEndResource["FEExpressions", 
       "HelpViewerToolbar"] | "Palette"]]]

...and continuing along like this you should hopefully be able to find notebook options that are specific only to the sort of notebooks you want to exclude, and once identified use that as a way of excluding the notebook.

share|improve this answer
Names["FrontEnd`*" ~~ "`" ... ~~ "Notebook"] // Column

gives

FrontEnd`ButtonNotebook
FrontEnd`ClipboardNotebook
FrontEnd`DebuggerStackNotebook
FrontEnd`EvaluationNotebook
FrontEnd`HelpBrowserNotebook
FrontEnd`InputNotebook
FrontEnd`MessagesNotebook
FrontEnd`SelectedNotebook
FrontEnd`SetSelectedNotebook

Of these, the following seem useful for filtering

useful = {(*FrontEnd`ClipboardNotebook,*)
  FrontEnd`DebuggerStackNotebook, FrontEnd`HelpBrowserNotebook, 
  FrontEnd`MessagesNotebook}

I have commented out ClipboardNotebook, as I do not know how it works. But probably it is useful. I thought HelpBrowserNotebook was not useful at first, but it is just something different than I expected. To generate a HelpBrowserNotebook, evaluate

FrontEndExecute[FrontEnd`HelpBrowserLookup["hello"]]

Then, a first filter, that you could combine with other answers, would be

Complement[Notebooks[], 
 Cases[FrontEndExecute[#[]] & /@ useful, _NotebookObject]]
share|improve this answer
    
I will take a look at it later :) I was wondering what were you looking for in tokens thresd :P –  Kuba Apr 23 at 13:17
    
@Kuba haha, well actually I wasn't looking for this, I just stumbled upon it :P. It all started with me finally modifying KeyEventTranslations.tr (I'm such a noob :( :p ) and finding some new tokens. –  Jacob Akkerboom Apr 23 at 13:19
1  

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.