Window
Use Window to control app windows. Every screen (i.e. display) combines to form a large rectangle. Every window lives within this rectangle and their position can be altered by giving coordinates inside this rectangle. To position a window to a specific display, you need to calculate its position within the large rectangle. To figure out the coordinates for a given screen, use the functions in Screen
. Beware that a window can get stale if you keep a reference to it and it is for instance closed while you do so.
Interface
class Window implements Identifiable
static Window focused()
static Window at(Point point)
static Array<Window> all(Map<String, AnyObject> optionals)
static Array<Window> recent()
Array<Window> others(Map<String, AnyObject> optionals)
String title()
boolean isMain()
boolean isNormal()
boolean isFullScreen()
boolean isMinimised() // or isMinimized()
boolean isVisible()
App app()
Screen screen()
Array<Space> spaces() // macOS 10.11+
Point topLeft()
Size size()
Rectangle frame()
boolean setTopLeft(Point point)
boolean setSize(Size size)
boolean setFrame(Rectangle frame)
boolean setFullScreen(boolean value)
boolean maximise() // or maximize()
boolean minimise() // or minimize()
boolean unminimise() // or unminimize()
Array<Window> neighbours(String direction) // or neighbors(...)
boolean raise()
boolean focus()
boolean focusClosestNeighbour(String direction) // or focusClosestNeighbor(...)
boolean close()
end
Static Methods
focused()
returns the focused window for the currently active app, can beundefined
if no window is focused currentlyat(Point point)
returns the topmost window at the specified point, can beundefined
if no window is present at the given positionall(Map<String, AnyObject> optionals)
returns all windows in screens if no optionals are givenrecent()
returns all visible windows in the order as they appear on the screen (from front to back), essentially returning them in the most-recently-used order
Window Optionals
visible
(boolean): if settrue
returns all visible windows in screens, if setfalse
returns all hidden windows in screens
Instance Methods
others(Map<String, AnyObject> optionals)
returns all other windows on all screens if no optionals are giventitle()
returns the title for the windowisMain()
returnstrue
if the window is the main window for its appisNormal()
returnstrue
if the window is a normal windowisFullScreen()
returnstrue
if the window is a full screen windowisMinimised()
orisMinimized()
returnstrue
if the window is minimisedisVisible()
returnstrue
if the window is a normal and unminimised window that belongs to an unhidden appapp()
returns the app for the windowscreen()
returns the screen where most or all of the window is currently present, can beundefined
if a window is out of bounds of any screenspaces()
returns the spaces where the window is currently present (macOS 10.11+, returns an empty list otherwise)topLeft()
returns the top left point for the windowsize()
returns the size for the windowframe()
returns the frame for the windowsetTopLeft(Point point)
sets the top left point for the window, returnstrue
if successfulsetSize(Size size)
sets the size for the window, returnstrue
if successfulsetFrame(Rectangle frame)
sets the frame for the window, returnstrue
if successfulsetFullScreen(boolean value)
sets whether the window is full screen, returnstrue
if successfulmaximise()
ormaximize()
resizes the window to fit the whole visible frame for the screen, returnstrue
if successfulminimise()
orminimize()
minimises the window, returnstrue
if successfulunminimise()
orunminimize()
unminimises the window, returnstrue
if successfulneighbours(String direction)
orneighbors(...)
returns windows to the direction (west|east|north|south
) of the windowraise()
makes the window the frontmost window of its app (but does not focus the app itself), returnstrue
if successfulfocus()
focuses the window, returnstrue
if successfulfocusClosestNeighbour(String direction)
orfocusClosestNeighbor(...)
focuses the closest window to the direction (west|east|north|south
) of the window, returnstrue
if successfulclose()
closes the window, returnstrue
if successful
Others Optionals
visible
(boolean): if settrue
returns visible windows, if setfalse
returns hidden windowsscreen
(Screen): returns all other windows on the specified screen
Events
See Events for a list of available events for Window.
Example
// Return all windows across all screens
const windows = Window.all();
// Move the focused window to origo
Window.focused().setTopLeft({ x: 0, y: 0 });
// Resize the focused window
Window.focused().setSize({ width: 1000, height: 500 });
// Resize the focused window to fill the full screen
Window.focused().maximise();