hammerspoon2-docs
    Preparing search index...

    Class HSApplication

    Object representing an application. You should not instantiate this directly in JavaScript, but rather, use the methods from hs.application which will return appropriate HSApplication objects.

    Index

    Constructors

    Properties

    allWindows: HSWindow[]

    All windows of this application

    bundleID: string | null

    Bundle Identifier (e.g. com.apple.Safari)

    bundlePath: string | null

    Location of the application on disk

    focusedWindow: HSWindow | null

    The focused window of this application, or nil if there is no focused window

    isActive: boolean

    Is the application focused

    isHidden: boolean

    Is the application hidden

    isRunning: boolean

    Whether the application process is still running

    kind: string

    The kind of application: "standard" (regular dock app), "accessory" (no dock), or "background" (agent)

    mainWindow: HSWindow | null

    The main window of this application, or nil if there is no main window

    pid: number

    POSIX Process Identifier

    title: string | null

    The application's title

    visibleWindows: HSWindow[]

    All visible (ie non-hidden) windows of this application

    Methods

    • Bring this application to the foreground

      Parameters

      • OptionalallWindows: boolean

        Pass true to raise all application windows. Defaults to false.

      Returns void

    • The application's HSAXElement object, for use with the hs.ax APIs

      Returns HSAXElement | null

      An HSAXElement object, or nil if it could not be obtained

    • Find a menu item by searching all menus for a matching title (case-insensitive)

      Parameters

      • name: string

        The menu item title to search for

      Returns Record<string, any> | null

      An object with title and enabled keys, or null if not found

    • Find a menu item by following a hierarchical path of titles

      Parameters

      • path: string[]

        An array of menu titles forming a path from the top-level menu to the item, e.g. ["Edit", "Select All"]

      Returns Record<string, any> | null

      An object with title and enabled keys, or null if not found

    • Find windows whose title contains the given string (case-insensitive)

      Parameters

      • pattern: string

        A string to search for in window titles

      Returns HSWindow[]

      An array of matching HSWindow objects

    • Get the full menu structure of this application

      Returns Record<string, any>[] | null

      An array of top-level menu objects, each with title and items keys, or null if unavailable

      This traverses the accessibility hierarchy and may be slow for apps with large menus.

    • Get the first window with exactly the given title

      Parameters

      • title: string

        The exact window title to search for

      Returns HSWindow | null

      The matching HSWindow, or null if not found

    • Hide this application and all its windows

      Returns void

    • Terminate the application

      Returns boolean

      True if the application was terminated, otherwise false

    • Force-terminate the application

      Returns boolean

      True if the application was force-terminated, otherwise false

    • Click a menu item found by searching all menus for a matching title (case-insensitive)

      Parameters

      • name: string

        The menu item title to search for

      Returns boolean

      true if the menu item was found and clicked, false otherwise

    • Click a menu item found by following a hierarchical path of titles

      Parameters

      • path: string[]

        An array of menu titles forming a path from the top-level menu to the item, e.g. ["File", "New Window"]

      Returns boolean

      true if the menu item was found and clicked, false otherwise

    • Unhide this application

      Returns void