hs.application
Module
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
Hammerspoon 2/Modules/hs.application/HSApplicationModule.swift:20
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
Hammerspoon 2/Modules/hs.application/HSApplicationModule.swift:25
Declaration
hs.application.matchingName(name) -> HSApplication
Parameters
-
namestringThe 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
Hammerspoon 2/Modules/hs.application/HSApplicationModule.swift:30
Declaration
hs.application.matchingBundleID(bundleID) -> HSApplication
Parameters
-
bundleIDstringThe 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
Hammerspoon 2/Modules/hs.application/HSApplicationModule.swift:35
Declaration
hs.application.fromPID(pid) -> HSApplication
Parameters
-
pidnumberThe PID to search for
Return Value
The matching application, or nil if none matched
hs.application.frontmost
Fetch the currently focused application
Hammerspoon 2/Modules/hs.application/HSApplicationModule.swift:39
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
Hammerspoon 2/Modules/hs.application/HSApplicationModule.swift:48
Declaration
hs.application.pathForBundleID(bundleID) -> string
Parameters
-
bundleIDstringThe 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
Hammerspoon 2/Modules/hs.application/HSApplicationModule.swift:53
Declaration
hs.application.pathsForBundleID(bundleID) -> string[]
Parameters
-
bundleIDstringThe 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
Hammerspoon 2/Modules/hs.application/HSApplicationModule.swift:64
Declaration
hs.application.pathForFileType(fileType) -> string
Parameters
-
fileTypestringThe 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
Hammerspoon 2/Modules/hs.application/HSApplicationModule.swift:69
Declaration
hs.application.pathsForFileType(fileType) -> string[]
Parameters
-
fileTypestringThe 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
Hammerspoon 2/Modules/hs.application/HSApplicationModule.swift:74
Declaration
hs.application.launchOrFocus(bundleID) -> Promise<boolean>
Parameters
-
bundleIDstringA 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
Hammerspoon 2/Modules/hs.application/HSApplicationModule.swift:80
Declaration
hs.application.addWatcher(event, listener) -> None
Parameters
-
eventstringThe event type to listen for
-
listenerJSValueA 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
Hammerspoon 2/Modules/hs.application/HSApplicationModule.swift:86
Declaration
hs.application.removeWatcher(event, listener) -> None
Parameters
-
eventstringThe event type to stop listening for
-
listenerJSValueThe javascript function/lambda that was previously being used to handle the event
Return Value
None