hammerspoon2-docs
    Preparing search index...

    Class HSWindowFilter

    A window filter: a set of rules choosing some of the windows on the system.

    Get the windows it allows with windows(), or listen for windows being created, moved, focused etc. with on(). Create one with hs.windowfilter.create().

    Listeners are called with the window, its application's name, and the event's name. They're only told about windows the filter allows, or has just stopped allowing (so they hear why it stopped).

    • windowCreated, windowDestroyed. A destroyed window has gone, so only its id can still be read (and its application's name is passed to the listener).
    • windowMoved: moved or resized, including going fullscreen
    • windowFullscreened, windowUnfullscreened
    • windowMinimized, windowUnminimized
    • windowHidden, windowUnhidden: its application was hidden or unhidden
    • windowVisible, windowNotVisible: it's visible when it's neither minimized nor hidden
    • windowInCurrentSpace, windowNotInCurrentSpace: whether it's on a Space currently shown. Minimized and hidden windows count as being in every Space.
    • windowOnScreen, windowNotOnScreen: whether it's actually on screen: visible, and in a Space currently shown
    • windowFocused, windowUnfocused
    • windowTitleChanged

    Five more events are about the filter's set of allowed windows:

    • windowAllowed: a window is now allowed. Emitted before any other event about it, e.g. before windowCreated for a new window.
    • windowRejected: a window is no longer allowed, or was destroyed. Emitted after the events that caused it.
    • hasWindow: the filter allows a window, having allowed none
    • hasNoWindows: the filter allows no windows any more. The listener gets the last one.
    • windowsChanged: the set of allowed windows changed. The listener gets one of the allowed windows, or null if there are none.

    Moves, resizes and title changes are reported once the window has stopped changing for a moment, so dragging a window emits one windowMoved, not hundreds.

    Index
    isPaused: boolean

    Whether this filter is paused

    rules: any

    This filter's rules, as an object hs.windowfilter.create() and setRules() accept, or null for a filter made from a function

    sortOrder: string

    How windows() sorts windows when not told otherwise: "focusedLast" (most recently focused first, the default), "focused", "createdLast" (newest first) or "created". Windows that existed before Hammerspoon started watching count as older than any created since, in order of their IDs, and as focused in their order on screen, front to back.

    • Allows an application's visible windows. The same as setAppRule(app, true).

      Parameters

      • app: string

        The application's name or bundle ID

      Returns HSWindowFilter

      This filter

    • A new filter with the same rules, which can then be changed without affecting this one

      Returns HSWindowFilter

      The new filter

    • Focuses the nearest window this filter allows that is to the right of a window

      Parameters

      • Optionaloptions: { frontmost?: boolean; strict?: boolean; window?: HSWindow } | null

        How to choose the windows

        • { frontmost?: boolean; strict?: boolean; window?: HSWindow }
          • Optionalfrontmost?: boolean

            true to put windows that can be seen before windows hidden behind others

          • Optionalstrict?: boolean

            true to only consider windows within 45° of the direction, rather than anywhere on that side of the window

          • Optionalwindow?: HSWindow

            The window to start from. Defaults to the focused window

        • null

      Returns boolean

      true if a window was focused, false if there was none to focus

    • Focuses the nearest window this filter allows that is above a window

      Parameters

      • Optionaloptions: { frontmost?: boolean; strict?: boolean; window?: HSWindow } | null

        How to choose the windows

        • { frontmost?: boolean; strict?: boolean; window?: HSWindow }
          • Optionalfrontmost?: boolean

            true to put windows that can be seen before windows hidden behind others

          • Optionalstrict?: boolean

            true to only consider windows within 45° of the direction, rather than anywhere on that side of the window

          • Optionalwindow?: HSWindow

            The window to start from. Defaults to the focused window

        • null

      Returns boolean

      true if a window was focused, false if there was none to focus

    • Focuses the nearest window this filter allows that is below a window

      Parameters

      • Optionaloptions: { frontmost?: boolean; strict?: boolean; window?: HSWindow } | null

        How to choose the windows

        • { frontmost?: boolean; strict?: boolean; window?: HSWindow }
          • Optionalfrontmost?: boolean

            true to put windows that can be seen before windows hidden behind others

          • Optionalstrict?: boolean

            true to only consider windows within 45° of the direction, rather than anywhere on that side of the window

          • Optionalwindow?: HSWindow

            The window to start from. Defaults to the focused window

        • null

      Returns boolean

      true if a window was focused, false if there was none to focus

    • Focuses the nearest window this filter allows that is to the left of a window

      Parameters

      • Optionaloptions: { frontmost?: boolean; strict?: boolean; window?: HSWindow } | null

        How to choose the windows

        • { frontmost?: boolean; strict?: boolean; window?: HSWindow }
          • Optionalfrontmost?: boolean

            true to put windows that can be seen before windows hidden behind others

          • Optionalstrict?: boolean

            true to only consider windows within 45° of the direction, rather than anywhere on that side of the window

          • Optionalwindow?: HSWindow

            The window to start from. Defaults to the focused window

        • null

      Returns boolean

      true if a window was focused, false if there was none to focus

    • Whether this filter could allow any of an application's windows: false if the application is rejected outright

      Parameters

      • app: string

        The application's name or bundle ID

      Returns boolean

      false if none of the application's windows can be allowed

    • Whether this filter allows a window

      Parameters

      Returns boolean

      true if the window is allowed

    • Removes a listener registered with on() or once()

      Parameters

      • event: HSWindowFilterEvent

        The event it was registered for

      • listener: (window: HSWindow | null, appName: string | null, event: string) => void

        The function originally registered

      Returns void

    • Registers a listener for an event about this filter's windows. A filter with listeners keeps working after you drop your reference to it, until its listeners are removed or it's paused.

      Parameters

      • event: HSWindowFilterEvent

        The event to listen for

      • listener: (window: HSWindow | null, appName: string | null, event: string) => void

        Called with the window, its application's name, and the event's name. Only windowsChanged passes nulls, when there are no windows left

      Returns void

      Throws an Error on failure; wrap calls in try/catch to handle it.

    • Registers a listener that's called once, the next time the event happens, then removed

      Parameters

      • event: HSWindowFilterEvent

        The event to listen for

      • listener: (window: HSWindow | null, appName: string | null, event: string) => void

        Called once

      Returns void

      Throws an Error on failure; wrap calls in try/catch to handle it.

    • Stops calling this filter's listeners, until resume(). Its listeners stay registered. A paused filter doesn't keep itself alive, so keep a reference to one you mean to resume.

      Returns HSWindowFilter

      This filter

    • Rejects all of an application's windows. The same as setAppRule(app, false).

      Parameters

      • app: string

        The application's name or bundle ID

      Returns HSWindowFilter

      This filter

    • Sets the rule for one application's windows, which replaces the default rule for them

      Parameters

      • app: string

        The application's name or bundle ID

      • rule: boolean | object | null

        true for its visible windows, false for none, an object of conditions (as for the default rule of hs.windowfilter.create()), or null to remove the application's rule so the default applies again

      Returns HSWindowFilter | null

      This filter

      Throws an Error on failure; wrap calls in try/catch to handle it.

    • Sets the override rule's currentSpace condition, leaving its other conditions alone

      Parameters

      • value: boolean | null

        true to allow only windows in the current Space (along with minimized and hidden windows, which belong to every Space), false to reject them, or null to ignore Spaces

      Returns HSWindowFilter

      This filter

    • Sets the rule for applications that have no rule of their own

      Parameters

      • rule: boolean | object | null

        true for visible windows, false for none, an object of conditions, or null for every window with a standard role

      Returns HSWindowFilter | null

      This filter

      Throws an Error on failure; wrap calls in try/catch to handle it.

    • Sets the rule every window must pass, whatever its application's rule says

      Parameters

      • rule: boolean | object | null

        true for visible windows only, false for none, an object of conditions, or null for no override rule

      Returns HSWindowFilter | null

      This filter

      Throws an Error on failure; wrap calls in try/catch to handle it.

    • Replaces all of this filter's rules

      Parameters

      • rules: object

        The rules, as for hs.windowfilter.create()

      Returns HSWindowFilter | null

      This filter

      Throws an Error on failure; wrap calls in try/catch to handle it.

    • The windows this filter allows, sorted

      Parameters

      • OptionalsortOrder: "focusedLast" | "focused" | "createdLast" | "created"

        How to sort them: most or least recently focused first, or newest or oldest first. Defaults to the filter's sortOrder

      Returns HSWindow[]

      The windows

    • The windows this filter allows that are to the right of a window, nearest first. Only windows on screen count, so combine this with a currentSpace rule (or use hs.windowfilter.currentSpaceFilter) to ignore windows on other Spaces cheaply.

      Parameters

      • Optionaloptions: { frontmost?: boolean; strict?: boolean; window?: HSWindow } | null

        How to choose the windows

        • { frontmost?: boolean; strict?: boolean; window?: HSWindow }
          • Optionalfrontmost?: boolean

            true to put windows that can be seen before windows hidden behind others

          • Optionalstrict?: boolean

            true to only consider windows within 45° of the direction, rather than anywhere on that side of the window

          • Optionalwindow?: HSWindow

            The window to start from. Defaults to the focused window

        • null

      Returns HSWindow[]

      The windows, nearest first

    • The windows this filter allows that are above a window, nearest first. Only windows on screen count, so combine this with a currentSpace rule (or use hs.windowfilter.currentSpaceFilter) to ignore windows on other Spaces cheaply.

      Parameters

      • Optionaloptions: { frontmost?: boolean; strict?: boolean; window?: HSWindow } | null

        How to choose the windows

        • { frontmost?: boolean; strict?: boolean; window?: HSWindow }
          • Optionalfrontmost?: boolean

            true to put windows that can be seen before windows hidden behind others

          • Optionalstrict?: boolean

            true to only consider windows within 45° of the direction, rather than anywhere on that side of the window

          • Optionalwindow?: HSWindow

            The window to start from. Defaults to the focused window

        • null

      Returns HSWindow[]

      The windows, nearest first

    • The windows this filter allows that are below a window, nearest first. Only windows on screen count, so combine this with a currentSpace rule (or use hs.windowfilter.currentSpaceFilter) to ignore windows on other Spaces cheaply.

      Parameters

      • Optionaloptions: { frontmost?: boolean; strict?: boolean; window?: HSWindow } | null

        How to choose the windows

        • { frontmost?: boolean; strict?: boolean; window?: HSWindow }
          • Optionalfrontmost?: boolean

            true to put windows that can be seen before windows hidden behind others

          • Optionalstrict?: boolean

            true to only consider windows within 45° of the direction, rather than anywhere on that side of the window

          • Optionalwindow?: HSWindow

            The window to start from. Defaults to the focused window

        • null

      Returns HSWindow[]

      The windows, nearest first

    • The windows this filter allows that are to the left of a window, nearest first. Only windows on screen count, so combine this with a currentSpace rule (or use hs.windowfilter.currentSpaceFilter) to ignore windows on other Spaces cheaply.

      Parameters

      • Optionaloptions: { frontmost?: boolean; strict?: boolean; window?: HSWindow } | null

        How to choose the windows

        • { frontmost?: boolean; strict?: boolean; window?: HSWindow }
          • Optionalfrontmost?: boolean

            true to put windows that can be seen before windows hidden behind others

          • Optionalstrict?: boolean

            true to only consider windows within 45° of the direction, rather than anywhere on that side of the window

          • Optionalwindow?: HSWindow

            The window to start from. Defaults to the focused window

        • null

      Returns HSWindow[]

      The windows, nearest first