#cp.app
This class assists with working with macOS apps. It provides functions for finding, checking the running status, version number, path, and many other values related to an application. It also provides support for launching, quitting, and other activities related to applications.
This extension differs from the hs.application
extension in several ways:
cp.app
instances are long-lived. You request it once and it will stay up-to-date even if the app quits.- It makes extensive use of
cp.prop
, so you canwatch
many most properties of the app and get live notifications when they change.
#Submodules
#API Overview
Variables - Configurable values
Functions - API calls offered directly by the extension
Constructors - API calls which return an object, typically one that offers API methods
Fields - Variables which can only be accessed from an object returned by a constructor
- baseLocale
- baseResourcesPath
- currentLocale
- description
- displayName
- focusedWindow
- focusedWindowUI
- frontmost
- hsApplication
- info
- installed
- isWindowAnimationEnabled
- localeResourcesPath
- mainWindowUI
- modalDialogOpen
- path
- pid
- preferences
- resourcesPath
- running
- showing
- supportedLocales
- UI
- version
- versionString
- windows
- windowsUI
Methods - API calls which can only be made on an object returned by a constructor
- bestSupportedLocale
- bundleID
- doHide
- doLaunch
- doQuit
- doRestart
- doShow
- hide
- icon
- isSupportedLocale
- keyStroke
- launch
- notifier
- quit
- registerWindowType
- searchResources
- show
- update
#API Documentation
#Variables
Signature | cp.app.frontmostApp <cp.prop: cp.app; read-only; live> |
Type | Variable |
Description | Returns the most recent 'registered' app that was active, other than CommandPost itself. |
Notes | None |
Source | src/extensions/cp//app.lua line 127 |
#Functions
Signature | cp.app.apps() -> table |
Type | Function |
Description | Returns a list of all apps that have been requested via forBundleID, in no particular order. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//app.lua line 108 |
Signature | cp.app.bundleIDs() -> table |
Type | Function |
Description | Returns a list of Bundle IDs which have been requested via forBundleID. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//app.lua line 91 |
Signature | cp.app.is(thing) -> boolean |
Type | Function |
Description | Checks if the provided thing is a cp.app instance. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//app.lua line 78 |
#Constructors
Signature | cp.app.forBundleID(bundleID) |
Type | Constructor |
Description | Returns the cp.app for the specified Bundle ID. If the app has already been created, the same instance of cp.app will be returned on subsequent calls. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//app.lua line 153 |
#Fields
Signature | cp.app.baseLocale <cp.prop: cp.i18n.localeID; read-only> |
Type | Field |
Description | Returns the localeID of the development region. This is the 'Base' locale for I18N. |
Notes | None |
Source | src/extensions/cp//app.lua line 603 |
Signature | cp.app.baseResourcesPath <cp.prop: string; read-only; live> |
Type | Field |
Description | A prop for the file path to the Content/Resources/Base.lproj folder |
Notes | None |
Source | src/extensions/cp//app.lua line 740 |
Signature | cp.app.currentLocale <cp.prop: cp.i18n.localeID; live> |
Type | Field |
Description | Gets and sets the current locale for the application. |
Notes | None |
Source | src/extensions/cp//app.lua line 647 |
Signature | cp.app.description -> string |
Type | Field |
Description | Returns the short description of the class as "cp.app: |
Notes | None |
Source | src/extensions/cp//app.lua line 1048 |
Signature | cp.app.displayName <cp.prop: string; read-only; live> |
Type | Field |
Description | The application display name as a string. |
Notes | None |
Source | src/extensions/cp//app.lua line 586 |
Signature | cp.app.focusedWindow <cp.prop: cp.ui.Window; read-only; live> |
Type | Field |
Description | The currently-focused Window. This may be a subclass of Window if |
Notes | None |
Source | src/extensions/cp//app.lua line 452 |
Signature | cp.app.focusedWindowUI <cp.prop: hs.axuielement; read-only; live> |
Type | Field |
Description | Returns the UI containing the currently-focused window for the app. |
Notes | None |
Source | src/extensions/cp//app.lua line 462 |
Signature | cp.app.frontmost <cp.prop: boolean; read-only; live> |
Type | Field |
Description | Is the application currently frontmost? |
Notes | None |
Source | src/extensions/cp//app.lua line 312 |
Signature | cp.app.hsApplication <cp.prop: hs.application; read-only; live> |
Type | Field |
Description | Returns the running hs.application for the application, or nil if it's not running. |
Notes | None |
Source | src/extensions/cp//app.lua line 245 |
Signature | cp.app.info <cp.prop: table; read-only; live> |
Type | Field |
Description | The info table for the application, if available. |
Notes | None |
Source | src/extensions/cp//app.lua line 533 |
Signature | cp.app.installed <cp.prop: boolean; read-only> |
Type | Field |
Description | Checks if the application currently installed. |
Notes | None |
Source | src/extensions/cp//app.lua line 596 |
Signature | cp.app.isWindowAnimationEnabled <cp.prop: bool; live> |
Type | Field |
Description | A prop that determines if window animations (eg. popups, etc.) are enabled for the |
Notes | None |
Source | src/extensions/cp//app.lua line 771 |
Signature | cp.app.localeResourcesPath <cp.prop: string; read-only; live> |
Type | Field |
Description | A prop for the file path to the locale-specific resources |
Notes | None |
Source | src/extensions/cp//app.lua line 751 |
Signature | cp.app.mainWindowUI <cp.prop: hs.axuielement; read-only; live> |
Type | Field |
Description | Returns the UI containing the currently-focused window for the app. |
Notes | None |
Source | src/extensions/cp//app.lua line 481 |
Signature | cp.app.modalDialogOpen <cp.prop: boolean; read-only> |
Type | Field |
Description | Checks if a modal dialog window is currently opon. |
Notes | None |
Source | src/extensions/cp//app.lua line 491 |
Signature | cp.app.path <cp.prop: string; read-only; live> |
Type | Field |
Description | Path to the application, or nil if not found. |
Notes | None |
Source | src/extensions/cp//app.lua line 504 |
Signature | cp.app.pid <cp.prop: number; read-only; live> |
Type | Field |
Description | Returns the PID for the currently-running application, or nil if it's not running. |
Notes | None |
Source | src/extensions/cp//app.lua line 267 |
Signature | cp.app.preferences <cp.app.prefs> |
Type | Field |
Description | The current preferences for the application. |
Notes | None |
Source | src/extensions/cp//app.lua line 238 |
Signature | cp.app.resourcesPath <cp.prop: string; read-only; live> |
Type | Field |
Description | A prop for the file path to the Contents/Resources folder inside the app. |
Notes | None |
Source | src/extensions/cp//app.lua line 730 |
Signature | cp.app.running <cp.prop: boolean; read-only; live> |
Type | Field |
Description | Checks if the application currently is running. |
Notes | None |
Source | src/extensions/cp//app.lua line 277 |
Signature | cp.app.showing <cp.prop: boolean; read-only; live> |
Type | Field |
Description | Is the app visible on screen? |
Notes | None |
Source | src/extensions/cp//app.lua line 299 |
Signature | cp.app.supportedLocales <cp.prop: table of cp.i18n.localeID; read-only; live> |
Type | Field |
Description | Returns a list of cp.i18n.localeID values for locales that are supported by this app. |
Notes | None |
Source | src/extensions/cp//app.lua line 614 |
Signature | cp.app.UI <cp.prop: hs.axuielement; read-only; live> |
Type | Field |
Description | Returns the application's axuielement , if available. |
Notes | None |
Source | src/extensions/cp//app.lua line 287 |
Signature | cp.app.version <cp.prop: semver; read-only; live> |
Type | Field |
Description | The application version as a semver. |
Notes |
|
Source | src/extensions/cp//app.lua line 573 |
Signature | cp.app.versionString <cp.prop: string; read-only; live> |
Type | Field |
Description | The application version as a string . |
Notes |
|
Source | src/extensions/cp//app.lua line 560 |
Signature | cp.app.windows <cp.prop: table of cp.ui.Window; read-only; live> |
Type | Field |
Description | Returns a list containing the Window instances currently available. |
Notes | None |
Source | src/extensions/cp//app.lua line 418 |
Signature | cp.app.windowsUI <cp.prop: table of hs.axuielement; read-only; live> |
Type | Field |
Description | Returns the UI containing the list of windows in the app. |
Notes | None |
Source | src/extensions/cp//app.lua line 432 |
#Methods
Signature | cp.app:bestSupportedLocale(locale) -> cp.i18n.localeID or nil |
Type | Method |
Description | Finds the closest match for the specified locale. The returned locale will be in the same language as the provided locale, and as close a match as possible with the region and script. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//app.lua line 1105 |
Signature | cp.app:bundleID() -> string |
Type | Method |
Description | Returns the Bundle ID for the app. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//app.lua line 198 |
Signature | cp.app:doHide() -> cp.rx.go.Statement <boolean> |
Type | Method |
Description | Returns a Statement which will hide the app if it's currently running. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//app.lua line 1017 |
Signature | cp.app:doLaunch([waitSeconds[, path]]) -> cp.rx.Statement <boolean> |
Type | Method |
Description | Returns a Statement that can be run to launch or focus the current app. It will resolve to true when the app was launched. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | src/extensions/cp//app.lua line 823 |
Signature | cp.app:doQuit() -> cp.rx.go.Statement <boolean> |
Type | Method |
Description | Returns a Statement that will attempt to quit the app when executed. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | src/extensions/cp//app.lua line 895 |
Signature | cp.app:doRestart() -> cp.rx.go.Statement <boolean> |
Type | Method |
Description | Returns a Statement which will attempt to restart the app. If the app was not running at the time, no action is taken and false is returned. If it was running then the app will be attempted to quit then restarted. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | src/extensions/cp//app.lua line 918 |
Signature | cp.app:doShow() -> cp.rx.go.Statement <boolean> |
Type | Method |
Description | Returns a Statement which will show the app if it's currently running. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//app.lua line 977 |
Signature | cp.app:hide() -> self |
Type | Method |
Description | Hides the application, if it's currently running. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//app.lua line 1000 |
Signature | cp.app:icon() -> image |
Type | Method |
Description | Returns the application icon as a hs.image |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//app.lua line 211 |
Signature | cp.app:isSupportedLocale(locale) -> boolean |
Type | Method |
Description | Checks if the specified locale is supported. The locale can be either a string with the locale code (eg. "en_AU") or a cp.i18n.localeID . |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//app.lua line 1083 |
Signature | cp.app:keyStroke(modifiers, character) -> none |
Type | Method |
Description | Generates and emits a single keystroke event pair for the supplied keyboard modifiers and character to the application. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//app.lua line 224 |
Signature | cp.app:launch([waitSeconds], [path]) -> self |
Type | Method |
Description | Launches the application, or brings it to the front if it was already running. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//app.lua line 786 |
Signature | cp.app:notifier() -> cp.ui.notifier |
Type | Method |
Description | Returns a notifier that is tracking the application UI element. It has already been started. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//app.lua line 1035 |
Signature | cp.app:quit(waitSeconds) -> self |
Type | Method |
Description | Asks the application to quit, if it's running. The app may not have actually quit after this function runs, even if true is returned. The application may take some time, or may be prompting the user for input, etc. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//app.lua line 875 |
Signature | cp.app:registerWindowType(windowClass[, options]) -> cp.app |
Type | Method |
Description | Registers the specified class as one which will be used when accessing a specific AXWindow instance. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | src/extensions/cp//app.lua line 325 |
Signature | cp.app:searchResources(value) -> hs.task |
Type | Method |
Description | Creates a hs.task which will search for the specified string value in the resources of the current app. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | src/extensions/cp//app.lua line 1163 |
Signature | cp.app:show() -> self |
Type | Method |
Description | Ensure the app is onscreen if it is currently running. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//app.lua line 955 |
Signature | cp.app:update() -> self |
Type | Method |
Description | Updates the app, triggering any watchers if values have changed. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | src/extensions/cp//app.lua line 1133 |