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

    Constructors

    Properties

    application: HSApplication | null

    The application that owns this window

    frame: HSRect | null

    The window's frame {x: Int, y: Int, w: Int, h: Int}

    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 {x: Int, y: Int}

    screen: HSScreen | null

    The screen that contains the largest portion of this window.

    size: HSSize | null

    The window's size {w: Int, h: Int}

    title: string | null

    The window's title

    Methods

    • 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.

      Returns boolean

      true if successful

    • Minimize this window

      Returns boolean

      true if successful

    • 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

    • Unminimize this window

      Returns boolean

      true if successful