Module for interacting with applications

Types

This module provides the following types:

Properties

This module has no properties.

Methods

hs.application.runningApplications

Fetch all running applications


Declaration

hs.application.runningApplications() -> HSApplication[]

Parameters

None

Return Value

An array of all currently running applications

hs.application.matchingName

Fetch the first running application that matches a name


Declaration

hs.application.matchingName(name) -> HSApplication

Parameters

  • name string

    The applicaiton name to search for

Return Value

The first matching application, or nil if none matched

hs.application.matchingBundleID

Fetch the first running application that matches a Bundle ID


Declaration

hs.application.matchingBundleID(bundleID) -> HSApplication

Parameters

  • bundleID string

    The identifier to search for

Return Value

The first matching application, or nil if none matched

hs.application.fromPID

Fetch the running application that matches a POSIX PID


Declaration

hs.application.fromPID(pid) -> HSApplication

Parameters

  • pid number

    The PID to search for

Return Value

The matching application, or nil if none matched

hs.application.frontmost

Fetch the currently focused application


Declaration

hs.application.frontmost() -> HSApplication

Parameters

None

Return Value

The matching application, or nil if none matched

hs.application.pathForBundleID

Fetch the filesystem path for an application


Declaration

hs.application.pathForBundleID(bundleID) -> string

Parameters

  • bundleID string

    The application bundle identifier to search for (e.g. "com.apple.Safari")

Return Value

The application's filesystem path, or nil if it was not found

hs.application.pathsForBundleID

Fetch filesystem paths for an application


Declaration

hs.application.pathsForBundleID(bundleID) -> string[]

Parameters

  • bundleID string

    The application bundle identifier to search for (e.g. "com.apple.Safari")

Return Value

An array of strings containing any filesystem paths that were found

hs.application.pathForFileType

Fetch filesystem path for an application able to open a given file type


Declaration

hs.application.pathForFileType(fileType) -> string

Parameters

  • fileType string

    The file type to search for. This can be a UTType identifier, a MIME type, or a filename extension

Return Value

The path to an application for the given filetype, or il if none were found

hs.application.pathsForFileType

Fetch filesystem paths for applications able to open a given file type


Declaration

hs.application.pathsForFileType(fileType) -> string[]

Parameters

  • fileType string

    The file type to search for. This can be a UTType identifier, a MIME type, or a filename extension

Return Value

An array of strings containing the filesystem paths for any applications that were found

hs.application.launchOrFocus

Launch an application, or give it focus if it's already running


Declaration

hs.application.launchOrFocus(bundleID) -> Promise<boolean>

Parameters

  • bundleID string

    A bundle identifier for the app to launch/focus (e.g. "com.apple.Safari")

Return Value

A Promise that resolves to true if successful, false otherwise

hs.application.addWatcher

Create a watcher for application events


Declaration

hs.application.addWatcher(event, listener) -> None

Parameters

  • event string

    The event type to listen for

  • listener JSValue

    A javascript function/lambda to call when the event is received. The function will be called with two parameters: the name of the event, and the associated HSApplication object

Return Value

None

hs.application.removeWatcher

Remove a watcher for application events


Declaration

hs.application.removeWatcher(event, listener) -> None

Parameters

  • event string

    The event type to stop listening for

  • listener JSValue

    The javascript function/lambda that was previously being used to handle the event

Return Value

None