Rule(desc)

A complex modification rule

Constructor

new Rule(desc)

Parameters:
Name Type Description
desc string

rule description

Source:
Rule.js, line 30

Classes

Rule

Members

conds object[]

Remap conditions.

Source:
Rule.js, line 68

desc string

Rule description.

Source:
Rule.js, line 58

remaps object[]

Remap definitions.

Source:
Rule.js, line 63

Methods

cond(cond)Rule

Defines a condition

Parameters:
Name Type Description
cond object

condition definition like: { type: 'variable_if', ... }

Source:
Rule.js, line 113
Returns:

this

Type:
Rule
Examples
let rule = new Rule('VSCode Rules')
  .cond(if_app('com.microsoft.VSCode'))
  .remap( ... )
  .remap( ... );
Remap rules only for VSCode
let rule = new Rule('VSCode Rules')
  .cond(if_var('foo', 1))  // if variable 'foo' is 1
  .cond(if_app('com.microsoft.VSCode'))
  .remap( ... )
  .remap( ... );
Multiple conditions

remap(map)Rule

Defines a from-to remap rule

Parameters:
Name Type Description
map object

Rule definition like: { from: ... , to: ... }

Properties
Name Type Description
from Keymap

An object like { key_code: 'a' }, or a string of the special expression. (See Keymap)

to

An object like { key_code: 'a' }, or a string of the special expression. Also can be an array for multiple keymaps. (See Keymap)

* any

Any property that Karabiner supports for manipulator

Source:
Rule.js, line 89
Returns:

itself

Type:
Rule
Examples
let rule = new Rule('control + H to backspace')
  .remap({
    from: key('h', 'control'),
    to:   key('delete_or_backspace')
  });
Remap control + H to backspace
let rule = new Rule('Various Remaps')
  .remap( ... )
  .remap( ... )
  .remap( ... );
Multiple remap rules

toJSON()object

Returns a plain object representation of this rule

Source:
Rule.js, line 123
Returns:

an object like: { description: ... , manipulators: ... }

Type:
object

staticfromJSON(data)Rule

Instantiates a Rule from the given JSON string or object.

Parameters:
Name Type Description
data
  • string
  • object

JSON string or object

Source:
Rule.js, line 36
Returns:

new instance

Type:
Rule