Skip to content
jigish edited this page Jan 24, 2013 · 60 revisions

Appetizer

Normally, the way Slate is configured, a truly dynamic operation is impossible.

For example, lets say I wanted the keystroke ctrl+1 to push the window to the right if the application of the current window is iTerm, push the window to the left if the application is Google Chrome, and push the window to the top if the application is anything else. Also, lets say I wanted it such that if the window's title is "OMG I WANT TO BE FULLSCREEN" we'll fullscreen the window regardless of the application. And again, I want the keystroke ctrl+1 to handle all of this. In the typical Slate config, this is impossible.

Enter JavaScript Configs:

// Create Operations
var pushRight = slate.operation("push", {
  "direction" : "right",
  "style" : "bar-resize:screenSizeX/3"
});
var pushLeft = slate.operation("push", {
  "direction" : "left",
  "style" : "bar-resize:screenSizeX/3"
});
var pushTop = slate.operation("push", {
  "direction" : "top",
  "style" : "bar-resize:screenSizeX/2"
});
var fullscreen = slate.operation("move", {
  "x" : "screenOriginX",
  "y" : "screenOriginY",
  "width" : "screenSizeX",
  "height" : "screenSizeY"
});
// Bind A Crazy Function to 1+ctrl
slate.bind("1:ctrl", function(win) {
  // here win is a reference to the currently focused window
  if (win.title() === "OMG I WANT TO BE FULLSCREEN") {
    win.doOperation(fullscreen);
    return;
  }
  var appName = win.app().name();
  if (appName === "iTerm") {
    win.doOperation(pushRight);
  } else if (appName === "Google Chrome") {
    win.doOperation(pushLeft);
  } else {
    win.doOperation(pushTop);
  }
});

Definitely verbose, but they can do much more than normal configs. Yum.

Main Course

Clone this wiki locally