# cp.commands.shortcut

Shortcut Commands


# Submodules


# API Overview

Functions - API calls offered directly by the extension

  • build
  • new

Fields - Variables which can only be accessed from an object returned by a constructor

  • isEnabled

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

  • bind
  • delete
  • disable
  • enable
  • getKeyCode
  • getModifiers
  • trigger
  • unbind

# API Documentation

# Functions

# build

Signature cp.commands.shortcut.build(receiverFn) -> cp.commands.shortcut.builder
Type Function
Description Creates a new shortcut builder.
Parameters
  • receiverFn - (optional) a function which will get passed the shortcut when the build is complete.
Returns
  • shortcut.builder which can be used to create the shortcut.
Notes
  • If provided, the receiver function will be called when the shortcut has been configured, and passed the new
  • shortcut. The result of that function will be returned to the next stage.
  • If no receiverFn is provided, the shortcut will be returned directly.
  • The builder is additive. You can create a complex keystroke combo by
  • chaining the shortcut names together.
  • For example:
  • local myShortcut = shortcut.build():cmd():alt("x")
  • Alternately, provide a receiver function and it will get passed the shortcut instead:
  • shortcut.build(function(shortcut) self._myShortcut = shortcut end):cmd():alt("x")
Examples None
Source src/extensions/cp/commands/shortcut.lua line 69

# new

Signature cp.commands.shortcut.new(modifiers, keyCode) -> shortcut
Type Function
Description Creates a new keyboard shortcut, attached to the specified hs.commands.command
Parameters
  • modifiers - The modifiers.
  • keyCode - The key code.
Returns
  • shortcut - The shortcut that was created.
Notes None
Examples None
Source src/extensions/cp/commands/shortcut.lua line 51

# Fields

# isEnabled

Signature cp.commands.shortcut:isEnabled <cp.prop: boolean>
Type Field
Description If true, the shortcut is enabled.
Notes None
Source src/extensions/cp/commands/shortcut.lua line 124

# Methods

# bind

Signature cp.commands.shortcut:bind(pressedFn, releasedFn, repeatedFn) -> shortcut
Type Method
Description This function binds the shortcut to a hotkey, with the specified callback functions for pressedFn, releasedFn and repeatedFn.
Parameters
  • pressedFn - (optional) If present, this is called when the shortcut combo is pressed.
  • releasedFn - (optional) If present, this is called when the shortcut combo is released.
  • repeatedFn - (optional) If present, this is called when the shortcut combo is repeated.
Returns
  • self
Notes
  • If the shortcut is enabled, the hotkey will also be enabled at this point.
Examples None
Source src/extensions/cp/commands/shortcut.lua line 169

# delete

Signature cp.commands.shortcut:delete() -> shortcut
Type Method
Description Deletes a shortcut.
Parameters
  • None
Returns
  • self
Notes None
Examples None
Source src/extensions/cp/commands/shortcut.lua line 231

# disable

Signature cp.commands.shortcut:disable() -> shortcut
Type Method
Description This disables the shortcut. If a hotkey has been bound, it will be disabled also.
Parameters
  • None
Returns
  • self
Notes None
Examples None
Source src/extensions/cp/commands/shortcut.lua line 155

# enable

Signature cp.commands.shortcut:enable() -> shortcut
Type Method
Description This enables the shortcut. If a hotkey has been bound, it will be enabled also.
Parameters
  • None
Returns
  • self
Notes None
Examples None
Source src/extensions/cp/commands/shortcut.lua line 141

# getKeyCode

Signature cp.commands.shortcut:getKeyCode() -> string
Type Method
Description Returns a string containing the keycode of the shortcut.
Parameters
  • None
Returns
  • string containing the keycode of the shortcut.
Notes None
Examples None
Source src/extensions/cp/commands/shortcut.lua line 111

# getModifiers

Signature cp.commands.shortcut:getModifiers() -> table
Type Method
Description Returns a table containing the modifiers for a shortcut.
Parameters
  • None
Returns
  • table containing the modifiers of the shortcut.
Notes None
Examples None
Source src/extensions/cp/commands/shortcut.lua line 98

# trigger

Signature cp.commands.shortcut:trigger([app]) -> shortcut
Type Method
Description This will trigger the keystroke specified in the shortcut.
Parameters
  • app - An optional hs.application object.
Returns
  • self
Notes None
Examples None
Source src/extensions/cp/commands/shortcut.lua line 244

# unbind

Signature cp.commands.shortcut:unbind() -> shortcut
Type Method
Description Unbinds a shortcut.
Parameters
  • None
Returns
  • self
Notes None
Examples None
Source src/extensions/cp/commands/shortcut.lua line 212