hs.window
ModuleModule for interacting with windows
Types
This module provides the following types:
Properties
This module has no properties.
Methods
hs.window.focusedWindow() -> HSWindow
Get the currently focused window
Declaration
hs.window.focusedWindow() -> HSWindow
Returns
HSWindow
The focused window, or nil if none
Example
const win = hs.window.focusedWindow()
console.log(win && win.title)
hs.window.allWindows() -> HSWindow[]
Get all windows from all applications
Declaration
hs.window.allWindows() -> HSWindow[]
Returns
HSWindow[]
An array of all windows
Example
const wins = hs.window.allWindows()
console.log(wins.length)
hs.window.visibleWindows() -> HSWindow[]
Get all visible (not minimized) windows
Declaration
hs.window.visibleWindows() -> HSWindow[]
Returns
HSWindow[]
An array of visible windows
Example
const vis = hs.window.visibleWindows()
hs.window.windowsForApp(app) -> HSWindow[]
Get windows for a specific application
Declaration
hs.window.windowsForApp(app) -> HSWindow[]
Parameters
| Name | Type | Description |
|---|---|---|
| app | HSApplication | An HSApplication object |
Returns
HSWindow[]
An array of windows for that application
Example
const app = hs.application.frontmost()
const wins = hs.window.windowsForApp(app)
hs.window.windowsOnScreen(screenIndex) -> HSWindow[]
Get all windows on a specific screen
Declaration
hs.window.windowsOnScreen(screenIndex) -> HSWindow[]
Parameters
| Name | Type | Description |
|---|---|---|
| screenIndex | number | The screen index (0 for main screen) |
Returns
HSWindow[]
An array of windows on that screen
Example
const wins = hs.window.windowsOnScreen(0)
hs.window.windowAtPoint(point) -> HSWindow
Get the window at a specific screen position
Declaration
hs.window.windowAtPoint(point) -> HSWindow
Parameters
| Name | Type | Description |
|---|---|---|
| point | HSPoint | An HSPoint containing the coordinates |
Returns
HSWindow
The topmost window at that position, or nil if none
Example
const win = hs.window.windowAtPoint({x: 500, y: 300})
hs.window.orderedWindows() -> HSWindow[]
Get ordered windows (front to back)
Declaration
hs.window.orderedWindows() -> HSWindow[]
Returns
HSWindow[]
An array of windows in z-order
Example
const wins = hs.window.orderedWindows()
hs.window.findByTitle(title) -> any
Find windows by title
Parameter title: The window title to search for. All windows with titles that include this string, will be matched
Declaration
hs.window.findByTitle(title) -> any
Parameters
| Name | Type | Description |
|---|---|---|
| title | any | The window title to search for. All windows with titles that include this string, will be matched |
Returns
any
An array of HSWindow objects with matching titles
hs.window.currentWindows() -> any
Get all windows for the current application
Declaration
hs.window.currentWindows() -> any
Returns
any
An array of HSWindow objects
hs.window.moveToLeftHalf(win) -> any
Move a window to left half of screen
Parameter win: An HSWindow object
Declaration
hs.window.moveToLeftHalf(win) -> any
Parameters
| Name | Type | Description |
|---|---|---|
| win | any | An HSWindow object |
Returns
any
True if the operation was successful, otherwise False
hs.window.moveToRightHalf(win) -> any
Move a window to right half of screen
Parameter win: An HSWindow object
Declaration
hs.window.moveToRightHalf(win) -> any
Parameters
| Name | Type | Description |
|---|---|---|
| win | any | An HSWindow object |
Returns
any
True if the operation was successful, otherwise False
hs.window.maximize(win) -> any
Maximize a window
Parameter win: An HSWindow object
Declaration
hs.window.maximize(win) -> any
Parameters
| Name | Type | Description |
|---|---|---|
| win | any | An HSWindow object |
Returns
any
True if the operation was successful, otherwise false
hs.window.cycleWindows() -> None
SKIP_DOCS
Declaration
hs.window.cycleWindows() -> None
Returns
None