Skip to main content
Inspiring
May 30, 2023
Question

Determine screen number of active document

  • May 30, 2023
  • 1 reply
  • 384 views

I'm using this code to center a window:

   var win = new Window("palette",'MyWindow:', [$.screens[0].right/2 - 253,$.screens[0].bottom/2 - 127, $.screens[0].right/2 + 253, $.screens[0].bottom/2 + 127]);

That will work if the active document is on monitor 1 ($.screens[0]), but if it is on monitor 2 or 3, it will show my window on monitor 1.

 

Is there a way to query what monitor (screen) the active document is using?

 

Thanks in advance.

    This topic has been closed for replies.

    1 reply

    Inspiring
    May 30, 2023

    Figured it out. Slightly different code and I can't verify since I don't have dual monitors right now, but ...

    Replacing $.screens[0].bottom with app.ScreenHeight or doc.ScreenHeight and replacing @$.screens[0].right with app.ScreenWidth or doc.ScreenWidth should center it on either the window that FrameMaker is on, or the window that the active document is on - which might not be the same thing.

    Inspiring
    May 30, 2023

    The above assumes your window is roughly 506W x 254H - otherwise, you have to change the constants also.

     

    easiest for me was using the normal window bounds until it looked correct and then taking the differences - i.e. 

    var win = new Window("palette",'MyWindow:', [15, 45, 525, 300]); // bounds = [left, top, right, bottom]