hammerspoon2-docs
    Preparing search index...

    Class HSWindow

    Object representing a window. You should not instantiate these directly, but rather, use the methods in hs.window to create them for you. Note that this type uses private macOS APIs

    Index
    application: HSApplication | null

    The application that owns this window

    frame: HSRect | null

    The window's frame, as an HSRect

    Setting frame, position or size briefly turns off the owning application's AXEnhancedUserInterface, and restores it afterwards. Some applications (Chromium and Electron ones in particular) otherwise animate the change, or end up at the wrong size.

    id: number

    The window's underlying ID. A value of 0 or -1 likely means no window ID could be determined.

    isFocused: boolean

    Whether the window is focused

    isFullscreen: boolean

    Whether the window is fullscreen

    isMinimized: boolean

    Whether the window is minimized

    isStandard: boolean

    Whether the window is standard (has a titlebar)

    isVisible: boolean

    Whether the window is visible (not minimized or hidden)

    pid: number

    The process ID of the application that owns this window

    position: HSPoint | null

    The window's position on screen, as an HSPoint

    screen: HSScreen | null

    The screen that contains the largest portion of this window.

    size: HSSize | null

    The window's size, as an HSSize

    spaces: HSSpace[]

    The spaces this window is on. That's usually one, but windows set to appear on every space are on all of them. Empty if Spaces are unavailable (see hs.screen.spacesAvailable()).

    title: string | null

    The window's title

    • Get the underlying AXElement

      Returns HSAXElement

      The accessibility element for this window

    • Make this window its application's main window

      This does not activate the application. If the application is already frontmost, the window comes to the front.

      Returns boolean

      true if successful

    • Center the window on the screen

      Returns void

    • Close this window

      Returns boolean

      true if successful

    • Focus this window

      The window becomes its application's main window, and the application is brought to the front with only this window raised. The application's other windows keep their place in the stacking order.

      The application finishes coming to the front after this returns, and some applications then bring a different window forward, so this makes the window main again 0.3 seconds later. That is skipped if another of the application's windows has been chosen in the meantime, or if focus() is called again.

      Returns boolean

      true if the window was made main and its application was brought to the front. The window

    • Minimize this window

      Returns boolean

      true if successful

    • Move and resize the window, reporting whether it succeeded

      The same as setting frame, except that the result tells you whether the window accepted the change.

      Parameters

      • frame: HSRect

        The window's new frame

      Returns boolean

      true if the window was moved and resized, otherwise false

    • Moves this window to another space, without switching to it. This works for any app's windows, and doesn't use Mission Control.

      Only windows on a desktop can be moved, and only to a desktop - not to or from a fullscreen space. Windows set to appear on every space can't be moved either.

      Parameters

      • space: HSSpace

        The desktop to move the window to

      Returns Promise<void>

      A Promise that resolves once the window is on that space, or

    • Raise this window to the front

      Returns boolean

      true if successful

    • Capture the current on-screen contents of this window as an image.

      Requires Screen Recording permission.

      Parameters

      • OptionalkeepTransparency: boolean

        Whether to preserve the window's alpha channel. If false (the default), transparent regions are filled with an opaque black background.

      Returns Promise<HSImage>

      Resolves with the captured image, or rejects if the capture fails (e.g. permission denied, or the window could no longer be located).

    • Toggle fullscreen mode

      Returns boolean

      true if successful

    • Returns a plain object describing this window, for JSON serialisation

      JSON.stringify() calls this automatically, so you rarely need to call it yourself.

      Returns Record<string, any>

      An object with the window's id, pid, title, application (the owning app's title), frame, isMinimized, isFullscreen and isStandard. Values that can't be read are null

    • Unminimize this window

      Returns boolean

      true if successful