Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What techniques are there for modifying/organizing/selecting/deleting cells? I understand Mathematica 9.0 has a Cells function but what techniques exist in Mathematica 8.0? The documentation for effectively using and modifying Cells seems quite limited.

share|improve this question
up vote 2 down vote accepted

Techniques for modifying cells in Mathematica 8.0

Deletes all output Cells

  FrontEnd`NotebookFind[nb, "Output", All, CellStyle, AutoScroll -> False], 

Sets all Cells background to Green.

  CurrentValue[#, Background] = Green;

retrieve a list of Cells


Find cell based on CellTags

CellPrint[TextCell["abcd", "Text", CellTags -> "tag"]]
> abcd 
NotebookLocate["tag"]; NotebookRead[EvaluationNotebook[]]
> Cell["abcd", "Text", GeneratedCell -> True, CellAutoOverwrite -> True,CellTags -> "tag"]

Set TaggingRules for Notebook

SetOptions[EvaluationNotebook[],TaggingRules -> "InputFieldState" -> "initial string"]

Get TaggingRules for Notebook

Options[EvaluationNotebook[]], TaggingRules]
CurrentValue[EvaluationNotebook[], TaggingRules]

another way to retrieve list of Cells

NotebookTools`NotebookScan[InputNotebook[], Function[

And the needed functions to get the examples to work:

ModifyCells[fun_] := (
  i = 0;
  length = Length[NotebookGet[EvaluationNotebook[]][[1]]] + 1;
  NotebookTools`NotebookScan[InputNotebook[], (
     If[i < length,
      fun[NotebookSelection[#], i++];,
     ) &

Will also retrieve a list of Cells

Cells[nb_] := (
  SelectionMove[nb, All, Notebook];
  content = NotebookRead[nb];
  SelectionMove[nb, All, Cell];

share|improve this answer
But Cells in v9 returns completely different objects as in v8 with your Cells function, so I guess usage further on will differ considerably too. – Sjoerd C. de Vries Jun 26 '13 at 21:56
I agree with @SjoerdC.deVries. If you want the list of cells you could also do First@NotebookGet – Rojo Jun 27 '13 at 21:23
@Rojo I see what you mean how would I make the following code work Map[(SetOptions[#, Background -> Green]) &, First[NotebookGet[]]] Basically loop through all the cells in Mathematica 8.0 and set the background green. – Liam Jun 27 '13 at 22:57
An option could be =-NotebookTools`NotebookScan[InputNotebook[], nb \[Function] CurrentValue[NotebookSelection[nb], Background] = Green] – Rojo Jun 27 '13 at 23:07
The NotebookScan function is very similar to your function, but it allows you to do something else while the cell is selected (instead of your NotebookRead). In this case, setting the background of the current selection to green – Rojo Jun 27 '13 at 23:09

Your Answer


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.