8

I just found that CurrentValue[$FrontEnd,"ScreenInformation"] will generate (some of) the symbols it uses as keys in the current context of the first evaluation (it might do so for other properties but "ScreenInformation" is the one I know of). To replicate evaluate the following in a fresh Kernel:

Block[{$Context = "testcontext`"},
     CurrentValue[$FrontEnd, "ScreenInformation"]
]
{{testcontext`ScreenArea -> {{66, 1920}, {0, 1200}}, 
  testcontext`FullScreenArea -> {{0, 1920}, {0, 1200}}, 
  testcontext`BitDepth -> 32, 
  testcontext`Resolution -> 
   96}, {testcontext`ScreenArea -> {{-1280, 0}, {0, 1024}}, 
  testcontext`FullScreenArea -> {{-1280, 0}, {0, 1024}}, 
  testcontext`BitDepth -> 32, testcontext`Resolution -> 96}}

From now on, CurrentValue seems to always return (some) symbols in that context:

CurrentValue[$FrontEnd, "ScreenInformation"]
{{testcontext`ScreenArea -> {{66, 1920}, {0, 1200}}, 
  FullScreenArea -> {{0, 1920}, {0, 1200}}, 
  testcontext`BitDepth -> 32, 
  Resolution -> 
   96}, {testcontext`ScreenArea -> {{-1280, 0}, {0, 1024}}, 
  FullScreenArea -> {{-1280, 0}, {0, 1024}}, 
  testcontext`BitDepth -> 32, Resolution -> 96}}

Which symbols are created in which context is somewhat random when I try it with 11.3 and seems to be different in a fresh frontend session than in a fresh kernel started from an existing frontend session.

Why is this a problem? If you will do something like:

ScreenArea /. First[CurrentValue[$FrontEnd, "ScreenInformation"]]

in another context than the original this might not work as the context of ScreenArea might not match.

  1. Would anyone agree that this is a bug?
  2. What are suggested workarounds?
Albert Retey
  • 23,585
  • 60
  • 104
  • That's probably related by the root of the problem: 102189 – Kuba May 19 '18 at 20:43
  • @Kuba: Yes, seems related. One additional problem here is that using strings instead of symbols does not work (at least I could not find any way to make it work). And of course your comment there about undocumentd feature does apply here as well... – Albert Retey May 21 '18 at 07:43

1 Answers1

7

my own current favorite workaround would be this:

"ScreenArea" /. Replace[
  CurrentValue[$FrontEnd, "ScreenInformation"],
  Verbatim[Rule][s_Symbol, v_] :> (SymbolName[s] -> v), {2}
]

it has the advantage that it should work independently on what context the symbols were generated in and it should work when the exact behavior will be changed (fixed?) in a future version. It will not only work when the symbols are generated in a specific well defined context but also when they will be changed to strings (as long as the names won't change). Of course I am still interested in other suggestions and any pointers to shortcomings of this solution...

Albert Retey
  • 23,585
  • 60
  • 104