Last active
July 3, 2018 03:20
-
-
Save cjea/5dce889967dce3d30ffdff76f2189c25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var resizeAndCenterWindow = function(widthPercentage) { | |
var xPercentageOffset = (100-widthPercentage)/2; | |
return S.op("move", { | |
"x" : "screenOriginX+(screenSizeX/100.0*"+xPercentageOffset+")", | |
"y" : "screenOriginY", | |
"width" : "screenSizeX/100.0*"+widthPercentage, | |
"height" : "screenSizeY" | |
}); | |
}; | |
var fullSizeWindow = slate.operation("corner", { | |
"direction" : "top-left", | |
"width" : "screenSizeX", | |
"height" : "screenSizeY" | |
}); | |
var resizeAndCenterWindowOps = [ | |
fullSizeWindow, | |
resizeAndCenterWindow(85), | |
resizeAndCenterWindow(70), | |
resizeAndCenterWindow(63), | |
resizeAndCenterWindow(55), | |
resizeAndCenterWindow(48), | |
resizeAndCenterWindow(40) | |
]; | |
var hint = slate.operation("hint", { | |
"characters" : "JKLASDFGHQWERTYUIOPZXCVBNM", | |
windowHintsDuration: 6 | |
}); | |
var FOCUS = { | |
iterm: slate.operation("focus", { | |
app: "iTerm2" | |
}), | |
chrome: slate.operation("focus", { | |
app: "Google Chrome" | |
}), | |
vsCode: slate.operation("focus", { | |
app: "Code" | |
}), | |
}; | |
var MOVE = { | |
southWest: slate.operation("move", { | |
"x" : 1, | |
"y" : "screenOriginY+(screenSizeY)*0.4", | |
"width" : "screenSizeX*0.6", | |
"height" : "screenSizeY*0.6" | |
}), | |
northWide: slate.operation("move", { | |
"x" : 1, | |
"y" : 0, | |
"width" : "screenSizeX*0.9", | |
"height" : "screenSizeY*0.4" | |
}), | |
southEast: slate.operation("move", { | |
"x" : "screenSizeX*0.6", | |
"y" : "screenOriginY+(screenSizeY)*0.4", | |
"width" : "screenSizeX*0.4", | |
"height" : "screenSizeY*0.6" | |
}), | |
leftHalf: slate.operation("move", { | |
"x" : 0, | |
"y" : 0, | |
"width" : "screenSizeX*0.5", | |
"height" : "screenSizeY" | |
}), | |
rightHalf: slate.operation("move", { | |
"x" : "screenSizeX*0.5", | |
"y" : 0, | |
"width" : "screenSizeX*0.5", | |
"height" : "screenSizeY" | |
}) | |
}; | |
var LAYOUT = { | |
normal: false, | |
develop: false, | |
onlyCode: false, | |
present: false, | |
livecode: false | |
}; | |
function setLayout(layout) { | |
LAYOUT = Object.keys(LAYOUT).reduce( | |
(acc, key) => { acc[key] = layout === key; return acc; }, | |
{} | |
); | |
} | |
slate.bind("j:ctrl;cmd", function(w) { | |
var title = w.app().name(); | |
if(title === "iTerm2") { | |
if(LAYOUT.normal) { w.doOperation(MOVE.southWest) } | |
else if(LAYOUT.develop) { w.doOperation(MOVE.northWide) } | |
else if(LAYOUT.onlyCode) { w.doOperation(MOVE.rightHalf) } | |
else if(LAYOUT.present) { w.doOperation(MOVE.leftHalf) } | |
} | |
else if(title === "Google Chrome") { | |
if(LAYOUT.normal) { w.doOperation(MOVE.northWide) } | |
else if(LAYOUT.develop) { w.doOperation(MOVE.southEast) } | |
else if(LAYOUT.present) { w.doOperation(MOVE.rightHalf) } | |
else if(LAYOUT.livecode) { w.doOperation(MOVE.rightHalf) } | |
} | |
else if(title === "Code") { | |
if(LAYOUT.normal) { w.doOperation(MOVE.southEast) } | |
else if(LAYOUT.develop) { w.doOperation(MOVE.southWest) } | |
else if(LAYOUT.onlyCode) { w.doOperation(MOVE.leftHalf) } | |
else if(LAYOUT.livecode) { w.doOperation(MOVE.leftHalf) } | |
} | |
}); | |
slate.bind("k:ctrl;cmd", resizeAndCenterWindowOps[0]); | |
slate.bind("f:ctrl;cmd", hint); | |
slate.bind("p:ctrl;cmd", slate.operation("sequence", { | |
operations: [ | |
[function(w) { setLayout("present") }], | |
[slate.operation("show", {app: ["iTerm2", "Google Chrome"]}), FOCUS.iterm], | |
[MOVE.leftHalf, FOCUS.chrome], | |
[MOVE.rightHalf, FOCUS.iterm] | |
] | |
})); | |
slate.bind("l:ctrl;cmd", slate.operation("sequence", { | |
operations: [ | |
[function(w) { setLayout("livecode") }], | |
[slate.operation("show", {app: ["Code", "Google Chrome"]}), FOCUS.chrome], | |
[MOVE.rightHalf, FOCUS.vsCode], | |
[MOVE.leftHalf] | |
] | |
})); | |
slate.bind("n:ctrl;cmd", slate.operation("sequence", { | |
operations: [ | |
[function(w) { setLayout("normal") }], | |
[slate.operation("show", {app: ["iTerm2", "Code", "Google Chrome"]}), FOCUS.vsCode], | |
[MOVE.southEast, FOCUS.iterm], | |
[MOVE.southWest, FOCUS.chrome], | |
[MOVE.northWide], | |
] | |
})); | |
slate.bind("d:ctrl;cmd", slate.operation("sequence", { | |
operations: [ | |
[function(w) { setLayout("develop") }], | |
[slate.operation("show", {app: ["iTerm2", "Code", "Google Chrome"]}), FOCUS.vsCode], | |
[MOVE.southWest, FOCUS.iterm], | |
[MOVE.northWide, FOCUS.chrome], | |
[MOVE.southEast, FOCUS.vsCode], | |
] | |
})); | |
slate.bind("o:ctrl;cmd", slate.operation("sequence", { | |
operations: [ | |
[function(w) { setLayout("onlyCode") }, FOCUS.iterm], | |
[MOVE.rightHalf, FOCUS.vsCode], | |
[MOVE.leftHalf], | |
] | |
})); | |
slate.bind("9:ctrl;cmd", resizeAndCenterWindowOps[1]); | |
slate.bind("8:ctrl;cmd", resizeAndCenterWindowOps[2]); | |
slate.bind("7:ctrl;cmd", resizeAndCenterWindowOps[3]); | |
slate.bind("6:ctrl;cmd", resizeAndCenterWindowOps[4]); | |
slate.bind("i:ctrl;alt", FOCUS.iterm); | |
slate.bind("i:ctrl;cmd", MOVE.southWest); | |
slate.bind("c:ctrl;alt", FOCUS.chrome); | |
slate.bind("c:ctrl;cmd", MOVE.northWide); | |
slate.bind("v:ctrl;alt", FOCUS.vsCode); | |
slate.bind("v:ctrl;cmd", MOVE.southEast); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment