API Docs

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.

Properties

bundleID

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

bundlePath

string
Location of the application on disk

mainWindow

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

focusedWindow

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

visibleWindows

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

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)

Methods

kill() -> boolean

Terminate the application
kill() -> boolean
boolean
True if the application was terminated, otherwise false
const app = hs.application.matchingName("Calculator")
app.kill()

kill9() -> boolean

Force-terminate the application
kill9() -> boolean
boolean
True if the application was force-terminated, otherwise false
const app = hs.application.matchingName("Calculator")
app.kill9()

axElement() -> HSAXElement

The application's HSAXElement object, for use with the hs.ax APIs
axElement() -> HSAXElement
HSAXElement
An HSAXElement object, or nil if it could not be obtained
const app = hs.application.frontmost()
const ax = app.axElement()

activate(allWindows) -> None

Bring this application to the foreground
activate(allWindows) -> None
Name Type Description
allWindows boolean Pass true to raise all application windows. Defaults to false.
None
const app = hs.application.matchingName("Safari")
app.activate()
app.activate(true)

hide() -> None

Hide this application and all its windows
hide() -> None
None
const app = hs.application.matchingName("Safari")
app.hide()

unhide() -> None

Unhide this application
unhide() -> None
None
const app = hs.application.matchingName("Safari")
app.unhide()

getMenuItems() -> [[String: Any]]

Get the full menu structure of this application
getMenuItems() -> [[String: Any]]
[[String: Any]]
An array of top-level menu objects, each with title and items keys, or null if unavailable
const app = hs.application.frontmost()
app.getMenuItems().forEach(m => console.log(m.title))

findMenuItemByName(name) -> [String: Any]

Find a menu item by searching all menus for a matching title (case-insensitive)
findMenuItemByName(name) -> [String: Any]
Name Type Description
name string The menu item title to search for
[String: Any]
An object with title and enabled keys, or null if not found
const app = hs.application.frontmost()
const item = app.findMenuItemByName("Select All")
console.log(item.enabled)

findMenuItemByPath(path) -> [String: Any]

Find a menu item by following a hierarchical path of titles
findMenuItemByPath(path) -> [String: Any]
Name Type Description
path string[] An array of menu titles forming a path from the top-level menu to the item, e.g. ["Edit", "Select All"]
[String: Any]
An object with title and enabled keys, or null if not found
const app = hs.application.frontmost()
const item = app.findMenuItemByPath(["Edit", "Select All"])
console.log(item.enabled)

selectMenuItemByName(name) -> boolean

Click a menu item found by searching all menus for a matching title (case-insensitive)
selectMenuItemByName(name) -> boolean
Name Type Description
name string The menu item title to search for
boolean
true if the menu item was found and clicked, false otherwise
const safari = hs.application.matchingName("Safari")
safari.selectMenuItemByName("New Window")

selectMenuItemByPath(path) -> boolean

Click a menu item found by following a hierarchical path of titles
selectMenuItemByPath(path) -> boolean
Name Type Description
path string[] An array of menu titles forming a path from the top-level menu to the item, e.g. ["File", "New Window"]
boolean
true if the menu item was found and clicked, false otherwise
const safari = hs.application.matchingName("Safari")
safari.selectMenuItemByPath(["File", "New Window"])

findWindow(pattern) -> HSWindow[]

Find windows whose title contains the given string (case-insensitive)
findWindow(pattern) -> HSWindow[]
Name Type Description
pattern string A string to search for in window titles
HSWindow[]
An array of matching HSWindow objects
const app = hs.application.frontmost()
app.findWindow("untitled").forEach(w => console.log(w.title))

getWindow(title) -> HSWindow

Get the first window with exactly the given title
getWindow(title) -> HSWindow
Name Type Description
title string The exact window title to search for
HSWindow
The matching HSWindow, or null if not found
const app = hs.application.frontmost()
const win = app.getWindow("index.html")