3
$\begingroup$

This is not a critical bug yet another issue that I should not waste time on.

Evaluate

SetOptions[EvaluationNotebook[]
 , WindowSize -> Automatic
 , WindowMargins -> 50
]

Question

I want to set the same options for a notebook that was saved with WindowSize -> Full (F12) without noticing it was saved in full screen. So via Visible->False.

path = FileNameJoin[{$TemporaryDirectory, "test.nb"}];
Export[path, Notebook[{}, WindowSize -> Full]]

nb = NotebookOpen[path, Visible -> False];

SetOptions[nb
 , WindowSize -> Automatic
 , WindowMargins -> 50     
 ];
SetOptions[nb, Visible -> True];

Problem on Win10

This does not work for me, nb is located on the left side of my screen with size of a default new notebook.

Commenters suggested doing SetOptions sequentially, which works, however

Problem persists on MacOSX 10.13+

and all my experiments lead me to a conclusion that:

In this OS you can't toggle full screen more when the notebook is Visible->False.


Can you reproduce this problem? Any tips?

$\endgroup$
2
  • $\begingroup$ I have reproduced the problem for both approaches using V11.2 on Win10. Note, however, that if I run either command, adjust the size or position of the newly opened window, and then run the command again (in either the old or new notebook), then the new notebook is resized properly. $\endgroup$
    – jjc385
    Commented Oct 21, 2017 at 14:31
  • $\begingroup$ SetOptions[nb, WindowSize -> Automatic]; SetOptions[nb, WindowMargins -> 50] also works. $\endgroup$ Commented Oct 21, 2017 at 15:56

2 Answers 2

2
$\begingroup$

Here is what I do and works everywhere so far.

Import notebook and filter options manually.

open[path_, opts___?OptionQ] := Module[{nbExpr, nb}
, nbExpr = Import[path, "NB"]
; nb = NotebookPut @ Notebook[
    First @ nbExpr
  , Sequence @@ (Normal @ <|Association @@ Rest[nbExpr], opts|>)
  ]
; NotebookSave[nb, path]
; nb
]

open[path, WindowSize -> Automatic, WindowMargins -> 50]
$\endgroup$
5
  • $\begingroup$ Isn't Sequence @@ Rest[nbExpr] equivalent to Sequence @@ (Normal @ <|Association @@ Rest[nbExpr]|>)? $\endgroup$ Commented Nov 4, 2017 at 10:21
  • $\begingroup$ @AlexeyPopkov yes, forgot opts. $\endgroup$
    – Kuba
    Commented Nov 4, 2017 at 10:23
  • 1
    $\begingroup$ Probably then Flatten[{opts, List @@ Rest[nbExpr]] should do the same, because opts will have higher precedence than Rest[nbExpr]. $\endgroup$ Commented Nov 4, 2017 at 10:25
  • $\begingroup$ @AlexeyPopkov good alternative for pre associations era. The only difference will be that here old opts are filtered out, not a major problem. $\endgroup$
    – Kuba
    Commented Nov 4, 2017 at 10:27
  • 1
    $\begingroup$ And more readable too, in my view. $\endgroup$ Commented Nov 4, 2017 at 10:28
1
$\begingroup$

The probable reason is that the Notebook FrontEnd and the Kernel do (historically) not wait for each other enough. Adding a Pause[] will slow things down and let the FronEnd (and probably the operating system) finish its work before the kernel interferes. You may have to use 1 second, but on my machine it works with 0.7. Not sure if this is a real satisfactory workaround, but it may give the good Wolfram folks an idea of how to fix it.

The following works for me on Windows and Mac OS 10.13 and Mathematica 11.2, no luck on Linux however.

path = FileNameJoin[{$TemporaryDirectory, "test.nb"}];
Export[path, Notebook[{}, WindowSize -> Full]];

nb = NotebookOpen[path, Visible -> False];

If[$OperatingSystem === "MacOSX", Pause[.8]];

SetOptions[nb
 , WindowSize -> Automatic
 , WindowMargins -> 50]; SetOptions[nb, Visible -> True
 ];
$\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.