-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathconductor.js
114 lines (97 loc) · 3.41 KB
/
conductor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Keith's [Conductor](https://github.com/keith/conductor) config
var padding = 2;
function windowToGrid(win, x, y, width, height) {
var screen = win.screen().frameIncludingDockAndMenu();
win.setFrame({
x: Math.round(x * screen.width) + padding + screen.x,
y: Math.round(y * screen.height) + padding + screen.y,
width: Math.round(width * screen.width) - (2 * padding),
height: Math.round(height * screen.height) - (2 * padding)
});
}
function toGrid(x, y, width, height) {
windowToGrid(Window.focusedWindow(), x, y, width, height);
}
Window.fullScreen = function() { toGrid(0, 0, 1, 1); }
Window.leftThird = function() { toGrid(0, 0, 0.33, 1); }
Window.leftHalf = function() { toGrid(0, 0, 0.5, 1); }
Window.rightHalf = function() { toGrid(0.5, 0, 0.5, 1); }
Window.topLeft = function() { toGrid(0, 0, 0.5, 0.5); }
Window.bottomLeft = function() { toGrid(0, 0.5, 0.5, 0.5); }
Window.topRight = function() { toGrid(0.5, 0, 0.5, 0.5); }
Window.bottomRight = function() { toGrid(0.5, 0.5, 0.5, 0.5); }
function center() {
var win = Window.focusedWindow();
var sframe = win.screen().frameWithoutDockOrMenu();
var frame = win.frame();
frame.x = sframe.x + ((sframe.width / 2) - (frame.width / 2));
frame.y = sframe.y + ((sframe.height / 2) - (frame.height / 2));
win.setFrame(frame);
}
function left() {
var win = Window.focusedWindow();
var frame = win.frame();
frame.x = 0;
win.setFrame(frame);
}
function right() {
var win = Window.focusedWindow();
var sframe = win.screen().frameWithoutDockOrMenu();
var frame = win.frame();
frame.x = sframe.width - frame.width;
win.setFrame(frame);
}
function push() {
var win = Window.focusedWindow();
var frame = win.frame();
var nextScreen = win.screen().nextScreen();
var screenFrame = nextScreen.frameWithoutDockOrMenu();
win.setFrame({
x: screenFrame.x,
y: screenFrame.y,
width: frame.width,
height: frame.height
});
}
function toggleAppIfOpen(title) {
var app = App.frontmostApp();
if (app.title() === title) {
app.hide();
} else {
var apps = App.runningApps().map(function(app) {
return app.title();
});
if (apps.indexOf(title) >= 0) {
api.launch(title);
}
}
}
function toggleApp(title) {
var app = App.frontmostApp();
if (app.title() === title) {
app.hide();
} else {
api.launch(title);
}
}
var modifiers = ["ctrl", "cmd"];
api.bind('u', modifiers, center);
api.bind('i', modifiers, left);
api.bind('o', modifiers, right);
api.bind('p', modifiers, push);
api.bind('k', modifiers, Window.fullScreen);
api.bind('t', modifiers, Window.leftThird);
api.bind('h', modifiers, Window.leftHalf);
api.bind('l', modifiers, Window.rightHalf);
api.bind('n', modifiers, Window.topLeft);
api.bind('m', modifiers, Window.bottomLeft);
api.bind(',', modifiers, Window.topRight);
api.bind('.', modifiers, Window.bottomRight);
api.bind('F1', [], function() { Screen.setBrightness(Screen.getBrightness() - 6.25); });
api.bind('F2', [], function() { Screen.setBrightness(Screen.getBrightness() + 6.25); });
api.bind('RETURN', ["shift", "cmd"], function() { toggleApp("Messages"); });
api.bind('d', ["ctrl", "alt"], function() { toggleApp("Dash"); });
api.bind('a', ["shift", "alt", "cmd"], function() { api.launch("Activity Monitor"); });
api.bind('c', ["shift", "alt", "cmd"], function() { api.launch("Console"); });
api.bind('c', ["ctrl", "cmd"], function() { toggleAppIfOpen("Ivory"); });
Config.hideMenuBar();