#
hs.window
Inspect/manipulate windows
Notes:
- See
hs.screenandhs.geometryfor more information on how Hammerspoon uses window/screen frames and coordinates
#
Submodules
#
API Overview
Variables - Configurable values
animationDuration setFrameCorrectness
Functions - API calls offered directly by the extension
allWindows desktop invisibleWindows list minimizedWindows orderedWindows setShadows snapshotForID timeout visibleWindows
Constructors - API calls which return an object, typically one that offers API methods
find focusedWindow frontmostWindow get
Methods - API calls which can only be made on an object returned by a constructor
application becomeMain centerOnScreen close focus focusTab focusWindowEast focusWindowNorth focusWindowSouth focusWindowWest frame id isFullScreen isMaximizable isMinimized isStandard isVisible maximize minimize move moveOneScreenEast moveOneScreenNorth moveOneScreenSouth moveOneScreenWest moveToScreen moveToUnit otherWindowsAllScreens otherWindowsSameScreen raise role screen sendToBack setFrame setFrameInScreenBounds setFrameWithWorkarounds setFullScreen setSize setTopLeft size snapshot subrole tabCount title toggleFullScreen toggleZoom topLeft unminimize windowsToEast windowsToNorth windowsToSouth windowsToWest zoomButtonRect
#
API Documentation
#
Variables
#
animationDuration
| Signature | hs.window.animationDuration (number) |
| Type | Variable |
| Description | The default duration for animations, in seconds. Initial value is 0.2; set to 0 to disable animations. |
| Notes | None |
| Source | extensions/window/window.lua line 21 |
#
setFrameCorrectness
| Signature | hs.window.setFrameCorrectness |
| Type | Variable |
| Description | Using hs.window:setFrame() in some cases does not work as expected: namely, the bottom (or Dock) edge, and edges between screens, might |
| Notes | None |
| Source | extensions/window/window.lua line 392 |
#
Functions
#
allWindows
| Signature | hs.window.allWindows() -> list of hs.window objects |
| Type | Function |
| Description | Returns all windows |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/window.lua line 54 |
#
desktop
| Signature | hs.window.desktop() -> hs.window object |
| Type | Function |
| Description | Returns the desktop "window" |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/window.lua line 33 |
#
invisibleWindows
| Signature | hs.window.invisibleWindows() -> list of hs.window objects |
| Type | Function |
| Description | Gets all invisible windows |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 139 |
#
list
| Signature | hs.window.list(allWindows) -> table |
| Type | Function |
| Description | Gets a table containing all the window data retrieved from CGWindowListCreate. |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/libwindow.m line 21 |
#
minimizedWindows
| Signature | hs.window.minimizedWindows() -> list of hs.window objects |
| Type | Function |
| Description | Gets all minimized windows |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 156 |
#
orderedWindows
| Signature | hs.window.orderedWindows() -> list of hs.window objects |
| Type | Function |
| Description | Returns all visible windows, ordered from front to back |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 173 |
#
setShadows
| Signature | hs.window.setShadows(shadows) |
| Type | Function |
| Description | Enables/Disables window shadows |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/libwindow.m line 563 |
#
snapshotForID
| Signature | hs.window.snapshotForID(ID [, keepTransparency]) -> hs.image-object |
| Type | Function |
| Description | Returns a snapshot of the window specified by the ID as an hs.image object |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/libwindow.m line 589 |
#
timeout
| Signature | hs.window.timeout(value) -> boolean |
| Type | Function |
| Description | Sets the timeout value used in the accessibility API. |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/libwindow.m line 65 |
#
visibleWindows
| Signature | hs.window.visibleWindows() -> list of hs.window objects |
| Type | Function |
| Description | Gets all visible windows |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 122 |
#
Constructors
#
find
| Signature | hs.window.find(hint) -> hs.window object(s) |
| Type | Constructor |
| Description | Finds windows |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/window.lua line 208 |
#
focusedWindow
| Signature | hs.window.focusedWindow() -> window |
| Type | Constructor |
| Description | Returns the window that has keyboard/mouse focus |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/libwindow.m line 94 |
#
frontmostWindow
| Signature | hs.window.frontmostWindow() -> hs.window object |
| Type | Constructor |
| Description | Returns the focused window or, if no window has focus, the frontmost one |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 748 |
#
get
| Signature | hs.window.get(hint) -> hs.window object |
| Type | Constructor |
| Description | Gets a specific window |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/window.lua line 189 |
#
Methods
#
application
| Signature | hs.window:application() -> app or nil |
| Type | Method |
| Description | Gets the hs.application object the window belongs to |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/libwindow.m line 482 |
#
becomeMain
| Signature | hs.window:becomeMain() -> window |
| Type | Method |
| Description | Makes the window the main window of its application |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/libwindow.m line 500 |
#
centerOnScreen
| Signature | hs.window:centerOnScreen([screen][, ensureInScreenBounds][, duration]) --> hs.window object |
| Type | Method |
| Description | Centers the window on a screen |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 864 |
#
close
| Signature | hs.window:close() -> bool |
| Type | Method |
| Description | Closes the window |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/libwindow.m line 324 |
#
focus
| Signature | hs.window:focus() -> hs.window object |
| Type | Method |
| Description | Focuses the window |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 508 |
#
focusTab
| Signature | hs.window:focusTab(index) -> bool |
| Type | Method |
| Description | Focuses the tab in the window's tab group at index, or the last tab if index is out of bounds |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/libwindow.m line 341 |
#
focusWindowEast
| Signature | hs.window:focusWindowEast([candidateWindows[, frontmost[, strict]]]) -> boolean |
| Type | Method |
| Description | Focuses the nearest possible window to the east (i.e. right) |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/window.lua line 783 |
#
focusWindowNorth
| Signature | hs.window:focusWindowNorth([candidateWindows[, frontmost[, strict]]]) -> boolean |
| Type | Method |
| Description | Focuses the nearest possible window to the north (i.e. up) |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/window.lua line 823 |
#
focusWindowSouth
| Signature | hs.window:focusWindowSouth([candidateWindows[, frontmost[, strict]]]) -> boolean |
| Type | Method |
| Description | Focuses the nearest possible window to the south (i.e. down) |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/window.lua line 843 |
#
focusWindowWest
| Signature | hs.window:focusWindowWest([candidateWindows[, frontmost[, strict]]]) -> boolean |
| Type | Method |
| Description | Focuses the nearest possible window to the west (i.e. left) |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/window.lua line 803 |
#
frame
| Signature | hs.window:frame() -> hs.geometry rect |
| Type | Method |
| Description | Gets the frame of the window in absolute coordinates |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 430 |
#
id
| Signature | hs.window:id() -> number or nil |
| Type | Method |
| Description | Gets the unique identifier of the window |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/libwindow.m line 546 |
#
isFullScreen
| Signature | hs.window:isFullScreen() -> bool or nil |
| Type | Method |
| Description | Gets the fullscreen state of the window |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/libwindow.m line 400 |
#
isMaximizable
| Signature | hs.window:isMaximizable() -> bool or nil |
| Type | Method |
| Description | Determines if a window is maximizable |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/libwindow.m line 296 |
#
isMinimized
| Signature | hs.window:isMinimized() -> bool |
| Type | Method |
| Description | Gets the minimized state of the window |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/libwindow.m line 456 |
#
isStandard
| Signature | hs.window:isStandard() -> bool |
| Type | Method |
| Description | Determines if the window is a standard window |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/libwindow.m line 164 |
#
isVisible
| Signature | hs.window:isVisible() -> boolean |
| Type | Method |
| Description | Determines if a window is visible (i.e. not hidden and not minimized) |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/window.lua line 243 |
#
maximize
| Signature | hs.window:maximize([duration]) -> hs.window object |
| Type | Method |
| Description | Maximizes the window |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/window.lua line 581 |
#
minimize
| Signature | hs.window:minimize() -> window |
| Type | Method |
| Description | Minimizes the window |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/libwindow.m line 417 |
#
move
| Signature | hs.window:move(rect[, screen][, ensureInScreenBounds][, duration]) --> hs.window object |
| Type | Method |
| Description | Moves the window |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 930 |
#
moveOneScreenEast
| Signature | hs.window:moveOneScreenEast([noResize, ensureInScreenBounds][, duration]) -> hs.window object |
| Type | Method |
| Description | Moves the window one screen east (i.e. right) |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 969 |
#
moveOneScreenNorth
| Signature | hs.window:moveOneScreenNorth([noResize, ensureInScreenBounds][, duration]) -> hs.window object |
| Type | Method |
| Description | Moves the window one screen north (i.e. up) |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 995 |
#
moveOneScreenSouth
| Signature | hs.window:moveOneScreenSouth([noResize, ensureInScreenBounds][, duration]) -> hs.window object |
| Type | Method |
| Description | Moves the window one screen south (i.e. down) |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 1009 |
#
moveOneScreenWest
| Signature | hs.window:moveOneScreenWest([noResize, ensureInScreenBounds][, duration]) -> hs.window object |
| Type | Method |
| Description | Moves the window one screen west (i.e. left) |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 982 |
#
moveToScreen
| Signature | hs.window:moveToScreen(screen[, noResize, ensureInScreenBounds][, duration]) -> hs.window object |
| Type | Method |
| Description | Moves the window to a given screen, retaining its relative position and size |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 904 |
#
moveToUnit
| Signature | hs.window:moveToUnit(unitrect[, duration]) -> hs.window object |
| Type | Method |
| Description | Moves and resizes the window to occupy a given fraction of the screen |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/window.lua line 887 |
#
otherWindowsAllScreens
| Signature | hs.window:otherWindowsAllScreens() -> list of hs.window objects |
| Type | Method |
| Description | Gets every window except this one |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 493 |
#
otherWindowsSameScreen
| Signature | hs.window:otherWindowsSameScreen() -> list of hs.window objects |
| Type | Method |
| Description | Gets other windows on the same screen |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 479 |
#
raise
| Signature | hs.window:raise() -> window |
| Type | Method |
| Description | Brings a window to the front of the screen without focussing it |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/libwindow.m line 521 |
#
role
| Signature | hs.window:role() -> string |
| Type | Method |
| Description | Gets the role of the window |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/libwindow.m line 147 |
#
screen
| Signature | hs.window:screen() -> hs.screen object |
| Type | Method |
| Description | Gets the screen which the window is on |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/window.lua line 618 |
#
sendToBack
| Signature | hs.window:sendToBack() -> hs.window object |
| Type | Method |
| Description | Sends the window to the back |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/window.lua line 539 |
#
setFrame
| Signature | hs.window:setFrame(rect[, duration]) -> hs.window object |
| Type | Method |
| Description | Sets the frame of the window in absolute coordinates |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 368 |
#
setFrameInScreenBounds
| Signature | hs.window:setFrameInScreenBounds([rect][, duration]) -> hs.window object |
| Type | Method |
| Description | Sets the frame of the window in absolute coordinates, possibly adjusted to ensure it is fully inside the screen |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 412 |
#
setFrameWithWorkarounds
| Signature | hs.window:setFrameWithWorkarounds(rect[, duration]) -> hs.window object |
| Type | Method |
| Description | Sets the frame of the window in absolute coordinates, using the additional workarounds described in hs.window.setFrameCorrectness |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/window.lua line 380 |
#
setFullScreen
| Signature | hs.window:setFullScreen(fullscreen) -> window |
| Type | Method |
| Description | Sets the fullscreen state of the window |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/libwindow.m line 382 |
#
setSize
| Signature | hs.window:setSize(size) -> window |
| Type | Method |
| Description | Resizes the window |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/libwindow.m line 239 |
#
setTopLeft
| Signature | hs.window:setTopLeft(point) -> window |
| Type | Method |
| Description | Moves the window to a given point |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/libwindow.m line 218 |
#
size
| Signature | hs.window:size() -> size |
| Type | Method |
| Description | Gets the size of the window |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/libwindow.m line 201 |
#
snapshot
| Signature | hs.window:snapshot([keepTransparency]) -> hs.image-object |
| Type | Method |
| Description | Returns a snapshot of the window as an hs.image object |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/libwindow.m line 611 |
#
subrole
| Signature | hs.window:subrole() -> string |
| Type | Method |
| Description | Gets the subrole of the window |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/libwindow.m line 127 |
#
tabCount
| Signature | hs.window:tabCount() -> number or nil |
| Type | Method |
| Description | Gets the number of tabs in the window has |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/libwindow.m line 362 |
#
title
| Signature | hs.window:title() -> string |
| Type | Method |
| Description | Gets the title of the window |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/libwindow.m line 110 |
#
toggleFullScreen
| Signature | hs.window:toggleFullScreen() -> hs.window object |
| Type | Method |
| Description | Toggles the fullscreen state of the window |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/window.lua line 597 |
#
toggleZoom
| Signature | hs.window:toggleZoom() -> window |
| Type | Method |
| Description | Toggles the zoom state of the window (this is effectively equivalent to clicking the green maximize/fullscreen button at the top left of a window) |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/libwindow.m line 257 |
#
topLeft
| Signature | hs.window:topLeft() -> point |
| Type | Method |
| Description | Gets the absolute co-ordinates of the top left of the window |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/libwindow.m line 184 |
#
unminimize
| Signature | hs.window:unminimize() -> window |
| Type | Method |
| Description | Un-minimizes the window |
| Parameters |
|
| Returns |
|
| Notes | None |
| Examples | None |
| Source | extensions/window/libwindow.m line 438 |
#
windowsToEast
| Signature | hs.window:windowsToEast([candidateWindows[, frontmost[, strict]]]) -> list of hs.window objects |
| Type | Method |
| Description | Gets all windows to the east of this window |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/window.lua line 688 |
#
windowsToNorth
| Signature | hs.window:windowsToNorth([candidateWindows[, frontmost[, strict]]]) -> list of hs.window objects |
| Type | Method |
| Description | Gets all windows to the north of this window |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/window.lua line 718 |
#
windowsToSouth
| Signature | hs.window:windowsToSouth([candidateWindows[, frontmost[, strict]]]) -> list of hs.window objects |
| Type | Method |
| Description | Gets all windows to the south of this window |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/window.lua line 733 |
#
windowsToWest
| Signature | hs.window:windowsToWest([candidateWindows[, frontmost[, strict]]]) -> list of hs.window objects |
| Type | Method |
| Description | Gets all windows to the west of this window |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/window.lua line 703 |
#
zoomButtonRect
| Signature | hs.window:zoomButtonRect() -> rect-table or nil |
| Type | Method |
| Description | Gets a rect-table for the location of the zoom button (the green button typically found at the top left of a window) |
| Parameters |
|
| Returns |
|
| Notes |
|
| Examples | None |
| Source | extensions/window/libwindow.m line 275 |