I'm trying to create a modified version of the Default.nb StyleSheet that adds a docked cell to act as a status bar along the top of every notebook to display some basic information (user login name and login time, generated when my set of packages is loaded). My current implementation, which isn't functioning as I want it to, assigns the cell data I want to display in the status bar to a variable in the Global context:

$StatusBar = ToBoxes[Dynamic[Row[{
        Style[$PersonName <> " logged in at " <> $LoginTime, 
         Darker[Darker[Green]], FontFamily -> "Arial"],
        Style["Not logged in!", Darker[Red], FontFamily -> "Arial"]
    TrackedSymbols :> {$PersonID, $PersonName, $LoginTime}]];

I've created a new stylesheet that inherits everything from Default.nb, but with modified Notebook Options Settings to add the desired DockedCells (I've omitted the non-relevant Options):


Unfortunately, the DockedCells Option defined in the StyleSheet doesn't seem to recognize the $StatusBar variable I've created to populate it. All I get is a docked cell displaying $StatusBar (verbatim). I'm not sure if this is a context issue, an evaluation order issue, or something else altogether.

It would be even more convenient if I could define the $StatusBar variable within the stylesheet so that it doesn't have to be recreated when my packages are loaded. However, I'm skeptical that this is possible. Is there any way to actually evaluate code within a StyleSheet?


I often create styles using CellPrint:

enter image description here

Once you have created the style definition go to Format > Edit Stylesheet and past this style definition cell into the private stylesheet:

enter image description here

You should then see the docked cell in your notebook:

enter image description here

But once you give values to your variables it should work

enter image description here

You should probably also remove some unwanted stuff from the style definition:

enter image description here

BTW you may want to choose a different test to ValueQ. I saw a Q&A the other day (can't remember which one) in which it does not always give what you expect due to

ValueQ gives False only if expr would not change if it were to be entered as Mathematica input.

  • $\begingroup$ Your suggestion above works fine if the contents of $StatusBar have been evaluated before executing the CellPrint statement that generates the StyleData cell. What I'm interested in is defining a new Default Stylesheet with that variable unevaluated (as it will be if I open a notebook to which the Stylesheet is applied before I load my packages), and having it populate when my packages are loaded. Is this possible? $\endgroup$ – bdot Nov 12 '13 at 2:57
  • $\begingroup$ Yes. But you should ask that in your question. $\endgroup$ – Mike Honeychurch Nov 12 '13 at 3:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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