#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 can watch 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

Methods - API calls which can only be made on an object returned by a constructor


#API Documentation

#Variables

Signaturecp.app.frontmostApp <cp.prop: cp.app; read-only; live>
TypeVariable
DescriptionReturns the most recent 'registered' app that was active, other than CommandPost itself.
NotesNone
Sourcesrc/extensions/cp//app.lua line 127

#Functions

Signaturecp.app.apps() -> table
TypeFunction
DescriptionReturns a list of all apps that have been requested via forBundleID, in no particular order.
Parameters
  • None
Returns
  • A list of cp.app instances.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 108

Signaturecp.app.bundleIDs() -> table
TypeFunction
DescriptionReturns a list of Bundle IDs which have been requested via forBundleID.
Parameters
  • None
Returns
  • A list of Bundle IDs.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 91

Signaturecp.app.is(thing) -> boolean
TypeFunction
DescriptionChecks if the provided thing is a cp.app instance.
Parameters
  • thing - The thing to check.
Returns
  • true if it is a cp.app instance, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 78

#Constructors

Signaturecp.app.forBundleID(bundleID)
TypeConstructor
DescriptionReturns 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
  • bundleID - The application bundle ID to find the app for.
Returns
  • The cp.app for the bundle.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 153

#Fields

Signaturecp.app.baseLocale <cp.prop: cp.i18n.localeID; read-only>
TypeField
DescriptionReturns the localeID of the development region. This is the 'Base' locale for I18N.
NotesNone
Sourcesrc/extensions/cp//app.lua line 603

Signaturecp.app.baseResourcesPath <cp.prop: string; read-only; live>
TypeField
DescriptionA prop for the file path to the Content/Resources/Base.lproj folder
NotesNone
Sourcesrc/extensions/cp//app.lua line 740

Signaturecp.app.currentLocale <cp.prop: cp.i18n.localeID; live>
TypeField
DescriptionGets and sets the current locale for the application.
NotesNone
Sourcesrc/extensions/cp//app.lua line 647

Signaturecp.app.description -> string
TypeField
DescriptionReturns the short description of the class as "cp.app: "
NotesNone
Sourcesrc/extensions/cp//app.lua line 1048

Signaturecp.app.displayName <cp.prop: string; read-only; live>
TypeField
DescriptionThe application display name as a string.
NotesNone
Sourcesrc/extensions/cp//app.lua line 586

Signaturecp.app.focusedWindow <cp.prop: cp.ui.Window; read-only; live>
TypeField
DescriptionThe currently-focused Window. This may be a subclass of Window if
NotesNone
Sourcesrc/extensions/cp//app.lua line 452

Signaturecp.app.focusedWindowUI <cp.prop: hs.axuielement; read-only; live>
TypeField
DescriptionReturns the UI containing the currently-focused window for the app.
NotesNone
Sourcesrc/extensions/cp//app.lua line 462

Signaturecp.app.frontmost <cp.prop: boolean; read-only; live>
TypeField
DescriptionIs the application currently frontmost?
NotesNone
Sourcesrc/extensions/cp//app.lua line 312

Signaturecp.app.hsApplication <cp.prop: hs.application; read-only; live>
TypeField
DescriptionReturns the running hs.application for the application, or nil if it's not running.
NotesNone
Sourcesrc/extensions/cp//app.lua line 245

Signaturecp.app.info <cp.prop: table; read-only; live>
TypeField
DescriptionThe info table for the application, if available.
NotesNone
Sourcesrc/extensions/cp//app.lua line 533

Signaturecp.app.installed <cp.prop: boolean; read-only>
TypeField
DescriptionChecks if the application currently installed.
NotesNone
Sourcesrc/extensions/cp//app.lua line 596

Signaturecp.app.isWindowAnimationEnabled <cp.prop: bool; live>
TypeField
DescriptionA prop that determines if window animations (eg. popups, etc.) are enabled for the
NotesNone
Sourcesrc/extensions/cp//app.lua line 771

Signaturecp.app.localeResourcesPath <cp.prop: string; read-only; live>
TypeField
DescriptionA prop for the file path to the locale-specific resources
NotesNone
Sourcesrc/extensions/cp//app.lua line 751

Signaturecp.app.mainWindowUI <cp.prop: hs.axuielement; read-only; live>
TypeField
DescriptionReturns the UI containing the currently-focused window for the app.
NotesNone
Sourcesrc/extensions/cp//app.lua line 481

Signaturecp.app.modalDialogOpen <cp.prop: boolean; read-only>
TypeField
DescriptionChecks if a modal dialog window is currently opon.
NotesNone
Sourcesrc/extensions/cp//app.lua line 491

Signaturecp.app.path <cp.prop: string; read-only; live>
TypeField
DescriptionPath to the application, or nil if not found.
NotesNone
Sourcesrc/extensions/cp//app.lua line 504

Signaturecp.app.pid <cp.prop: number; read-only; live>
TypeField
DescriptionReturns the PID for the currently-running application, or nil if it's not running.
NotesNone
Sourcesrc/extensions/cp//app.lua line 267

Signaturecp.app.preferences <cp.app.prefs>
TypeField
DescriptionThe current preferences for the application.
NotesNone
Sourcesrc/extensions/cp//app.lua line 238

Signaturecp.app.resourcesPath <cp.prop: string; read-only; live>
TypeField
DescriptionA prop for the file path to the Contents/Resources folder inside the app.
NotesNone
Sourcesrc/extensions/cp//app.lua line 730

Signaturecp.app.running <cp.prop: boolean; read-only; live>
TypeField
DescriptionChecks if the application currently is running.
NotesNone
Sourcesrc/extensions/cp//app.lua line 277

Signaturecp.app.showing <cp.prop: boolean; read-only; live>
TypeField
DescriptionIs the app visible on screen?
NotesNone
Sourcesrc/extensions/cp//app.lua line 299

Signaturecp.app.supportedLocales <cp.prop: table of cp.i18n.localeID; read-only; live>
TypeField
DescriptionReturns a list of cp.i18n.localeID values for locales that are supported by this app.
NotesNone
Sourcesrc/extensions/cp//app.lua line 614

Signaturecp.app.UI <cp.prop: hs.axuielement; read-only; live>
TypeField
DescriptionReturns the application's axuielement, if available.
NotesNone
Sourcesrc/extensions/cp//app.lua line 287

Signaturecp.app.version <cp.prop: semver; read-only; live>
TypeField
DescriptionThe application version as a semver.
Notes
  • If the application is running it will get the version of the active application as a string, otherwise, it will use hs.application.infoForBundleID() to find the version.
Sourcesrc/extensions/cp//app.lua line 573

Signaturecp.app.versionString <cp.prop: string; read-only; live>
TypeField
DescriptionThe application version as a string.
Notes
  • If the application is running it will get the version of the active application as a string, otherwise, it will use hs.application.infoForBundleID() to find the version.
Sourcesrc/extensions/cp//app.lua line 560

Signaturecp.app.windows <cp.prop: table of cp.ui.Window; read-only; live>
TypeField
DescriptionReturns a list containing the Window instances currently available.
NotesNone
Sourcesrc/extensions/cp//app.lua line 418

Signaturecp.app.windowsUI <cp.prop: table of hs.axuielement; read-only; live>
TypeField
DescriptionReturns the UI containing the list of windows in the app.
NotesNone
Sourcesrc/extensions/cp//app.lua line 432

#Methods

Signaturecp.app:bestSupportedLocale(locale) -> cp.i18n.localeID or nil
TypeMethod
DescriptionFinds 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
  • locale - The local to match
Returns
  • The closest supported locale or nil if none are available in the language.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 1105

Signaturecp.app:bundleID() -> string
TypeMethod
DescriptionReturns the Bundle ID for the app.
Parameters
  • None
Returns
  • The Bundle ID.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 198

Signaturecp.app:doHide() -> cp.rx.go.Statement <boolean>
TypeMethod
DescriptionReturns a Statement which will hide the app if it's currently running.
Parameters
  • None
Returns
  • A Statement, resolving to true if the app is running and was successfully hidden, or false otherwise.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 1017

Signaturecp.app:doLaunch([waitSeconds[, path]]) -> cp.rx.Statement <boolean>
TypeMethod
DescriptionReturns a Statement that can be run to launch or focus the current app. It will resolve to true when the app was launched.
Parameters
  • waitSeconds - (optional) The number of seconds to wait for it to load. Defaults to 30 seconds.
  • path - (optional) The alternate path of the app to launch.
Returns
  • The Statement, resolving to true after the app is frontmost.
Notes
  • By default the Statement will time out after 30 seconds, sending an error signal.
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 823

Signaturecp.app:doQuit() -> cp.rx.go.Statement <boolean>
TypeMethod
DescriptionReturns a Statement that will attempt to quit the app when executed.
Parameters
  • None.
Returns
  • The Statement, resolving to true if the app was running and was quit successfully, otherwise false.
Notes
  • The Statement will time out after 60 seconds by default. This can be changed by calling the TimeoutAfter method on the Statement before executing.
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 895

Signaturecp.app:doRestart() -> cp.rx.go.Statement <boolean>
TypeMethod
DescriptionReturns 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
  • None.
Returns
  • The Statement, resolving to true if the app was running and was quit and restarted successfully, otherwise false.
Notes
  • The Statement will time out after 60 seconds by default. This can be changed by calling the TimeoutAfter method on the Statement before executing.
  • If you have multiple versions of the same app on your system, this will restart with the same version that was running when the restart was requested.
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 918

Signaturecp.app:doShow() -> cp.rx.go.Statement <boolean>
TypeMethod
DescriptionReturns a Statement which will show the app if it's currently running.
Parameters
  • None
Returns
  • A Statement, resolving to true if the app is running and was successfully shown, or false otherwise.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 977

Signaturecp.app:hide() -> self
TypeMethod
DescriptionHides the application, if it's currently running.
Parameters
  • None
Returns
  • The cp.app instance.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 1000

Signaturecp.app:icon() -> image
TypeMethod
DescriptionReturns the application icon as a hs.image
Parameters
  • None
Returns
  • The icon as a hs.image object
NotesNone
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 211

Signaturecp.app:isSupportedLocale(locale) -> boolean
TypeMethod
DescriptionChecks 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
  • locale - The locale code string or localeID to check.
Returns
  • true if it is supported, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 1083

Signaturecp.app:keyStroke(modifiers, character) -> none
TypeMethod
DescriptionGenerates and emits a single keystroke event pair for the supplied keyboard modifiers and character to the application.
Parameters
  • modifiers - A table containing the keyboard modifiers to apply ("fn", "ctrl", "alt", "cmd" or "shift")
  • character - A string containing a character to be emitted
Returns
  • None
NotesNone
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 224

Signaturecp.app:launch([waitSeconds], [path]) -> self
TypeMethod
DescriptionLaunches the application, or brings it to the front if it was already running.
Parameters
  • waitSeconds - If provided, the number of seconds to wait until the launch completes. If nil, it will return immediately.
  • path - An optional full path to an application without an extension (i.e /Applications/Final Cut Pro 10.3.4). This allows you to load previous versions of the application.
Returns
  • The cp.app instance.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 786

Signaturecp.app:notifier() -> cp.ui.notifier
TypeMethod
DescriptionReturns a notifier that is tracking the application UI element. It has already been started.
Parameters
  • None
Returns
  • The notifier.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 1035

Signaturecp.app:quit(waitSeconds) -> self
TypeMethod
DescriptionAsks 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
  • waitSeconds - If povided, the number of seconds to wait until the quit completes. If nil, it will return immediately.
Returns
  • The cp.app instance.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 875

Signaturecp.app:registerWindowType(windowClass[, options]) -> cp.app
TypeMethod
DescriptionRegisters the specified class as one which will be used when accessing a specific AXWindow instance.
Parameters
  • windowClass - The class that will be used to create the window. It should be a subclass of Window
  • options - (optional) if provided, it will be passed the hs.asm.axuielement being wrapped, and should return true or false.
Returns
  • the same instance of the cp.app for further configuration.
Notes
  • Options:
  • matches: a function that will receive the AXWindow instance and should return true or false.
  • persistent: if set to true, the Window instance will be cached and checked when windows appear and disappear.
  • By default, it will use the matches function on the class itself to check. An alternate function can be provided by putting it in the {matches = <function>} property of the options table.
  • By default, Windows instances are assumed to be short-lived, and will not persist beyond the window opening or closing.
  • To indicate that it should stick around, add persistent = true to the options table.
  • If the new AXWindow matches, this class will be used when requesting the set of windows via the [#windows] method or the [#focusedWindow] or [#mainWindow] props.
  • Classes registered later will supersede those registered earlier, so ensure that matchers are specific enough to not recognise more window UIs than they should.
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 325

Signaturecp.app:searchResources(value) -> hs.task
TypeMethod
DescriptionCreates a hs.task which will search for the specified string value in the resources of the current app.
Parameters
  • value - The string value to search for.
Returns
  • hs.task which is already running, searching for the value. Results will be output in the Error Log.
Notes
  • This may take some time to complete, depending on how many resources the app contains.
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 1163

Signaturecp.app:show() -> self
TypeMethod
DescriptionEnsure the app is onscreen if it is currently running.
Parameters
  • None
Returns
  • The cp.app instance.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 955

Signaturecp.app:update() -> self
TypeMethod
DescriptionUpdates the app, triggering any watchers if values have changed.
Parameters
  • None
Returns
  • The cp.app instance.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp//app.lua line 1133