Function Repository Resource:

CloseOtherNotebooks

Source Notebook

Close all other open notebooks

Contributed by: Richard Hennigan (Wolfram Research)

ResourceFunction["CloseOtherNotebooks"][]

closes all but the current notebook.

ResourceFunction["CloseOtherNotebooks"][notebooks]

closes all notebooks except for those specified by notebooks.

Details and Options

The current notebook is determined by EvaluationNotebook[].
In ResourceFunction["CloseOtherNotebooks"][spec], the notebook specification spec can be an explicit NotebookObject, a pattern or a list of notebook specifications.
ResourceFunction["CloseOtherNotebooks"] takes the following options:
"Modified"Falsewhether to close notebooks that have unsaved changes

Examples

Basic Examples (3) 

Close all but the current notebook:

In[1]:=
CreateWindow[WindowTitle -> "Close Me"];
Notebooks[]
Out[2]=
In[3]:=
ResourceFunction["CloseOtherNotebooks"][]
Out[3]=

Only the current notebook and the messages window remain open:

In[4]:=
Notebooks[]
Out[4]=

Provide a list of notebooks that should be kept open:

In[5]:=
CreateWindow[WindowTitle -> "Close Me"];
nb = CreateWindow[WindowTitle -> "Keep Me Open"];
ResourceFunction["CloseOtherNotebooks"][{SelectedNotebook[], nb}]
Out[7]=
In[8]:=
Notebooks[]
Out[8]=
In[9]:=
ResourceFunction["CloseOtherNotebooks"][]
Out[9]=

Use a pattern to choose which notebooks to keep open:

In[10]:=
CreateWindow[WindowTitle -> "Close Me"];
CreateWindow[WindowTitle -> "Keep Me Open"];
ResourceFunction["CloseOtherNotebooks"][
 EvaluationNotebook[] | (nb_ /; CurrentValue[nb, WindowTitle] === "Keep Me Open")]
Out[12]=
In[13]:=
Notebooks[]
Out[13]=
In[14]:=
ResourceFunction["CloseOtherNotebooks"][]
Out[14]=

Options (2) 

Modified (2) 

By default, notebooks that have been modified in memory will not be closed:

In[15]:=
CreateWindow[WindowTitle -> "Close Me"];
nb = CreateWindow[WindowTitle -> "This one has been modified"];
NotebookWrite[nb, "testing"];
ResourceFunction["CloseOtherNotebooks"][]
Out[18]=
In[19]:=
Notebooks[]
Out[19]=

Using "Modified"True will close these notebooks without saving changes:

In[20]:=
ResourceFunction["CloseOtherNotebooks"]["Modified" -> True]
Out[20]=
In[21]:=
Notebooks[]
Out[21]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 31 December 2018

Related Resources

License Information