Button

Last updated 4 months ago

Button Module.

API Overview

  • 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

Functions

matches

Signature

cp.ui.Button.matches(element) -> boolean

Type

Function

Description

Checks if the element is a Button, returning true if so.

Parameters

element - The hs._asm.axuielement to check.

Returns

true if the element is a Button, or false if not.

Constructors

new

Signature

cp.ui.Button.new(parent, finderFn) -> cp.ui.Button

Type

Constructor

Description

Creates a new Button instance.

Parameters

parent - The parent object. Should have a UI and isShowing field. * finderFn - A function which will return the hs._asm.axuielement the button belongs to, or nil if not available.

Returns

The new Button instance.

Fields

frame

Signature

cp.ui.Button.frame <cp.prop: table; read-only>

Type

Field

Description

Returns the table containing the x, y, w, and h values for the button frame, or nil if not available.

isShowing

Signature

cp.ui.Button.isShowing <cp.prop: boolean; read-only>

Type

Field

Description

If true, the Button is showing on screen.

title

Signature

cp.ui.Button.title <cp.prop: string; read-only>

Type

Field

Description

The button title, if available.

UI

Signature

cp.ui.Button.UI <cp.prop: hs._asm.axuielement; read-only>

Type

Field

Description

Retrieves the axuielement for the Button, or nil if not available..

Methods

app

Signature

cp.ui.Button:app() -> App

Type

Method

Description

Returns the app instance.

Parameters

None

Returns

App

doPress

Signature

cp.ui.Button:doPress() -> cp.rx.go.Statement

Type

Method

Description

Returns a Statement that will press the button when executed, if available at the time.

Parameters

None

Returns

The Statement which will press the button when executed.

isEnabled

Signature

cp.ui.Button:isEnabled() -> boolean

Type

Method

Description

Returns true if the button is visible and enabled.

Parameters

None

Returns

true if the button is visible and enabled.

parent

Signature

cp.ui.Button:parent() -> parent

Type

Method

Description

Returns the parent object.

Parameters

None

Returns

parent

press

Signature

cp.ui.Button:press() -> self, boolean

Type

Method

Description

Performs a button press action, if the button is available.

Parameters

None

Returns

The Button instance. * true if the button was actually pressed successfully.

snapshot

Signature

`cp.ui.Button:snapshot([path]) -> hs.image

nil` </span>

Type

Method

Description

Takes a snapshot of the button in its current state as a PNG and returns it.

Parameters

path - (optional) The path to save the file. Should include the extension (should be .png).