# Applying a stylesheet to a notebook using a setterbar - palette hiccup

I built a setterbar that allows me to quickly apply stylesheets to a notebook. Here is the code:

SetterBar[Dynamic[temp], {"Lecture", "Testing"}],

Dynamic[If[temp == "Lecture",
SetOptions[InputNotebook[],
StyleDefinitions ->
"/Users/michaelmccain/Library/Mathematica/SystemFiles/FrontEnd/\
StyleSheets/MyLectureStyles.nb"],
SetOptions[InputNotebook[],
StyleDefinitions ->
"/Users/michaelmccain/Library/Mathematica/SystemFiles/FrontEnd/\
StyleSheets/Testing.nb"]]]


When the code is located in the target notebook it works perfectly. See gif below.

However, if I put the code above into a palette, then I get an annoying hiccup when I try and use it... The styles in the notebook don't update immediately. If I type at least one character in any cell, then the styles update. Strange. Below is gif illustrating the issue.

I'm not sure why. What is going on here? Is there a fix you can think of?

• A workaround is to add NotebookWrite[InputNotebook[],""] after SetOptions[]. This resets everything. I'm interested if anyone thinks this is a bug. – Michael McCain Dec 19 '16 at 0:17
• I've faced it too. I'm doing SetOptions[nb, StyleDefinitions->"Default.nb"] as an intermediate step and it works. That day it was one of minor problems so I forgot to report it. You can do that. – Kuba Dec 19 '16 at 7:36