Skip to content

Instantly share code, notes, and snippets.

@fimmtiu
Last active January 19, 2016 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fimmtiu/8d0b832fa319d5da21fd to your computer and use it in GitHub Desktop.
Save fimmtiu/8d0b832fa319d5da21fd to your computer and use it in GitHub Desktop.
fimmtiu's .slate.js file
// These make windows take up the left half and right half of the screen, respectively.
// I use this for Chrome windows on my Cinema Display.
var halfLeftVertical = slate.operation("push", {
"screen": "0",
"direction": "left",
"style": "bar-resize:screenSizeX/2"
});
var halfRightVertical = slate.operation("push", {
"screen": "0",
"direction": "right",
"style": "bar-resize:screenSizeX/2"
});
// "0" if there's only one screen, "1" if there's two.
var rightScreen = function() {
return (slate.screenCount() - 1).toString();
};
// This tiles my Chrome windows to the left and right sides of the screen.
// Unfortunately, there's no way for Slate to tell Chrome windows apart, so
// it'll randomly assign a side to each window. If I don't like the way
// they're assigned, I can click on the window I want on the left and hit
// "f6" again to swap them.
var chromeCount = 0;
var desktopChrome = function (win) {
if (win.title().length > 0) {
var op = (chromeCount % 2 == 0) ? halfLeftVertical : halfRightVertical;
chromeCount += 1;
win.doOperation(op);
}
};
// Full screen on the laptop monitor.
var moveHipChat = function() {
slate.operation("move", {
"screen": rightScreen(),
"x": "screenOriginX",
"y": "screenOriginY",
"width": "screenSizeX",
"height": "screenSizeY"
});
};
// Most of the screen on the Cinema Display.
var desktopEmacs = slate.operation("move", {
"screen": "0",
"x": "screenOriginX+631",
"y": "screenOriginY",
"width": 1929,
"height": 1415
});
var laptopFullscreen = slate.operation("move", {
"screen": "0",
"x": "screenOriginX",
"y": "screenOriginY",
"width": "screenSizeX",
"height": "screenSizeY"
});
// I have three Terminal windows, tiled left to right, overlapping.
var desktopTerminalOperations = {
"1": {screen: "0", x: "screenOriginX", y: "screenOriginY", width: 1030, height: 1344},
"2": {screen: "0", x: "screenOriginX+921", y: "screenOriginY", width: 1030, height: 1344},
"3": {screen: "0", x: "screenOriginX+1590", y: "screenOriginY", width: 970, height: 1344}
};
var laptopTerminalOperations = {
"1": {screen: "0", x: "screenOriginX", y: "screenOriginY", width: 1030, height: "screenSizeY"},
"2": {screen: "0", x: "screenOriginX+197", y: "screenOriginY", width: 1030, height: "screenSizeY"},
"3": {screen: "0", x: "screenOriginX+470", y: "screenOriginY", width: 970, height: "screenSizeY"}
};
// I set the "Preferences -> Windows -> Command Key" option on the
// terminals to include the window number in the title bar, and then choose
// what position to use based on the title.
var desktopTerminal = function(win) {
var index = win.title()[win.title().length - 1];
win.doOperation(slate.operation("move", desktopTerminalOperations[index]));
};
var laptopTerminal = function(win) {
var index = win.title()[win.title().length - 1];
win.doOperation(slate.operation("move", laptopTerminalOperations[index]));
};
// Laptop monitor, roughly centred, not full screen.
var moveITunes = function() {
slate.operation("move", {
"screen": rightScreen(),
"x": "screenOriginX+167",
"y": "screenOriginY+62",
"width": 1117,
"height": 725
});
};
// Adium has two windows, a contact window and a chat window.
var moveAdiumContacts = function() {
slate.operation("move", {
"screen": rightScreen(),
"x": "screenOriginX",
"y": "screenOriginY",
"width": 258,
"height": 295
});
};
var moveAdiumChat = function() {
slate.operation("move", {
"screen": rightScreen(),
"x": "screenOriginX",
"y": "screenOriginY+391",
"width": 400,
"height": 485
});
};
var laptop = slate.layout("laptop", {
"Google Chrome": {
"operations": [laptopFullscreen],
"ignore-fail": true,
"repeat": true
},
"Adium": {
"operations": [moveAdiumContacts, moveAdiumChat],
"title-order": ["Contacts"],
"ignore-fail": true
},
"Terminal": {
"operations": [laptopTerminal],
"repeat": true
},
"HipChat": {"operations": [moveHipChat]},
"Emacs": {"operations": [laptopFullscreen]},
"iTunes": {"operations": [moveITunes]}
});
var desktop = slate.layout("desktop", {
"_before_": {operations: [function () { chromeCount = 0 }]},
"Google Chrome": {
"operations": [desktopChrome],
"ignore-fail": true,
"repeat": true
},
"Adium": {
"operations": [moveAdiumContacts, moveAdiumChat],
"title-order": ["Contacts"],
"ignore-fail": true
},
"Terminal": {
"operations": [desktopTerminal],
"repeat": true
},
"HipChat": {"operations": [moveHipChat]},
"Emacs": {"operations": [desktopEmacs]},
"iTunes": {"operations": [moveITunes]}
});
// "f5" restores all windows to my laptop layout; "f6" restores the desktop layout.
// Useful for if I accidentally move windows. (Yes, I'm obsessive.)
slate.bind("f5", slate.operation("layout", {name: laptop}));
slate.bind("f6", slate.operation("layout", {name: desktop}));
// If there's only one monitor present, use the laptop layout; if there are
// two monitors, use the desktop layout.
slate.default(1, laptop);
slate.default(2, desktop);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment