1

I'd like to programmatically save (and then temporarily change and restore) specific printing options. I get as far as

Options[Notebook, PrintingOptions]

but don't know what to do next to extract specific options, for example PrintingMargins, from the (long) resulting list.

orome
  • 12,819
  • 3
  • 52
  • 100
  • Doesn't "PrintingMargins" /. (PrintingOptions /. Options[Notebook, PrintingOptions]) work for you? – J. M.'s missing motivation Nov 15 '12 at 23:20
  • @J.M.: That works. There's no API for extracting nested options? – orome Nov 15 '12 at 23:21
  • API, nothing. What would be the trouble with using ReplaceAll anyway? – J. M.'s missing motivation Nov 15 '12 at 23:44
  • @J.M.: No problem, I just expected something more compact and targeted to options. – orome Nov 15 '12 at 23:54
  • 4
    You kids today don't know how good you've got it! When I were a lad, ReplaceAll was all we had for option handling! We'd make six nested replacements to process our options, with Hold and Release for evaluation control, and Block our only scoping construct. And we were thankful! – Oleksandr R. Nov 16 '12 at 00:15
  • It can't be this: OptionValue[ OptionValue[Options[Notebook, PrintingOptions], "PrintingOptions"], "PrintingMargins"]. Maybe ReplaceAll is better after all. – orome Nov 16 '12 at 00:22

1 Answers1

3
 CurrentValue[Notebook, {PrintingOptions, "PrintingMargins"}]
 (* {{54, 54}, {72, 72}} *) 

You can also use $FrontEnd , EvaluationNotebook[] ... as the first argument.

Other examples:

 CurrentValue[$FrontEnd, EvaluatorNames]
 (* {"Local" -> {"AutoStartOnLaunch" -> True}} *)
 CurrentValue[$FrontEnd, {EvaluatorNames, "Local"}]
 (* {"AutoStartOnLaunch" -> True} *)
 CurrentValue[$FrontEnd, {EvaluatorNames, "Local", "AutoStartOnLaunch"}]
 (* True *)

Update: See also this Q/A: Items known by CurrentValue.

kglr
  • 394,356
  • 18
  • 477
  • 896