1
$\begingroup$

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.

$\endgroup$
6
  • $\begingroup$ Doesn't "PrintingMargins" /. (PrintingOptions /. Options[Notebook, PrintingOptions]) work for you? $\endgroup$ Nov 15, 2012 at 23:20
  • $\begingroup$ @J.M.: That works. There's no API for extracting nested options? $\endgroup$
    – orome
    Nov 15, 2012 at 23:21
  • $\begingroup$ API, nothing. What would be the trouble with using ReplaceAll anyway? $\endgroup$ Nov 15, 2012 at 23:44
  • $\begingroup$ @J.M.: No problem, I just expected something more compact and targeted to options. $\endgroup$
    – orome
    Nov 15, 2012 at 23:54
  • 4
    $\begingroup$ 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! $\endgroup$ Nov 16, 2012 at 0:15

1 Answer 1

3
$\begingroup$
 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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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