Skip to content
jigish edited this page Jan 25, 2013 · 20 revisions

Layouts are used to describe a set of operations that run together that you can reference in the layout operation and the slate.default function. This page describes them in detail.

Usage

Layouts are created using the slate.layout function

var name = slate.layout(name, description);

Layouts are used in the slate.default function

slate.default(screenConfig, layoutName);

This will cause the layout with the name layoutName to be activated when Slate sees the screen configuration described by screenConfig.

Layouts can also be used in the slate.operation function along with the layout operation

var layoutOperation = slate.operation("layout", layoutName);

This will create an operation that activates the layout with the name layoutName.

Description

When creating layouts using the slate.layout function, two parameters are needed: the name of the layout and a hash containing the description of the layout.

name

The layout name should be a String and cannot be undefined. e.g. "myLayout"

description

The layout description should be a hash (cannot be undefined) in the following form:

{
  app : params,
  app : params,
  ...
}
app

The name of the Application. This must be a String. e.g. "iTerm"

You may also specify one of the following special application names:

  • "_before_" - this specifies what to do before the layout is activated
  • "_after_" - this specifies what to do after the layout is activated
params

A hash that contains a description of what to do with the Application.

{
  "operations" : arrayOfOperationsOrFunctions,
  "ignore-fail" : ignoreFail,
  "repeat" : repeat,
  "repeat-last" : repeatLast,
  "main-first" : mainFirst,
  "main-last" : mainLast,
  "sort-title" : sortTitle,
  "title-order" : titleOrder,
  "title-order-regex" : titleOrderRegex
}
  • arrayOfOperationsOrFunctions - an Array containing any number of operation objects and/or functions. These operations or functions will be applied sequentially to windows within the Application starting with the window that was (or is) focused most recently. If an operation fails, the window will be skipped and the operation will be performed on the next window Slate sees within the Application. If there are more windows than there are elements in this array, the windows beyond the number of elements in this array will not have any operations performed on them.
  • ignoreFail - (optional) if true, Slate will move on to the next operation or function in arrayOfOperationsOrFunctions even if the operation failed.
  • repeat - (optional) if true, Slate will repeat the operations in arrayOfOperationsOrFunctions until all windows have had an operation performed on them. Does not work with repeatLast.
  • repeatLast - (optional) if true, Slate will repeat the last operation in arrayOfOperationsOrFunctions until all windows have had an operation performed on them. Does not work with repeat
  • main-first - (optional) if true, Slate will reorder the windows such that the main window will have an operation applied on it first. Does not work with main-last.
  • main-last - (optional) if true, Slate will reorder the windows such that the main window will have an operation applied on it last. Does not work with main-first.
  • sort-title - (optional) if true, Slate will reorder the windows such that they are sorter by title alphabetically increasing.
  • title-order - (optional) must be undefined or an Array of window titles. If this is specified, Slate will start applying operations on windows based on the order specified in the String. Windows with titles not in the String will be after those with titles in the String. Does not work with title-order-regex.
  • title-order-regex - (optional) similar to title-order except you may specify a Regular Expression to match the titles against instead of the entire title. Note that once a match is seen, the next Regular Expression will be used to match. This means if you have two windows that match the same Regular Expression, only the first one will be matched. The second will not. Does not work with title-order.

Note: you may only specify the arrayOfOperationsOrFunctions when using the special application names "_before_" and "_after_".

Example

var hideSpotify = slate.operation("hide", { "app" : "Spotify" });
var focusITerm = slate.operation("focus", { "app" : "iTerm" });
slate.layout("myLayout", {
  "_before_" : { "operations" : hideSpotify },
  "_after_" : {"operations" : focusITerm },
  "Adium" : {
    "ignore-fail" : true,
    "title-order" : []
  },
  "MacVim" : {
    "repeat" : true
  }
});

Clone this wiki locally