-
Notifications
You must be signed in to change notification settings - Fork 1
/
phoenix-1.5.js
172 lines (153 loc) · 4.58 KB
/
phoenix-1.5.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/**
* Phoenix 1.5 (quite old) config file
*/
function centerWindowInFrame(window, targetFrame) {
var windowFrame = window.frame(),
targetFrameCenter = {
x: targetFrame.x + targetFrame.width / 2,
y: targetFrame.y + targetFrame.height / 2,
};
window.setTopLeft({
x: targetFrameCenter.x - windowFrame.width / 2,
y: targetFrameCenter.y - windowFrame.height / 2,
});
}
function maximizeWindowInFrame(window, targetFrame) {
window.setFrame(targetFrame);
}
function windowFitsInFrame(window, targetFrame) {
var windowFrame = window.frame();
return (
windowFrame.width <= targetFrame.width &&
windowFrame.height <= targetFrame.height
);
}
function bindLaunch(key, modifiers, appName) {
api.bind(key, modifiers, function() {
api.launch(appName);
});
}
function frameOfNextScreen(window) {
if (!window || !window.screen().nextScreen()) {
return;
}
return window
.screen()
.nextScreen()
.frameWithoutDockOrMenu();
}
var debugMode = true;
function debug(message) {
if (debugMode) api.alert(message);
}
/***********************************************
* BINDINGS
***********************************************/
debugMode = false;
var triple = ["ctrl", "alt", "cmd"];
api.bind("space", triple, function() {
debug("Maximizing current window");
Window.focusedWindow().maximize();
});
api.bind("t", triple, function() {
debug("Showing title");
api.alert(
Window.focusedWindow()
.app()
.title(),
3
);
});
api.bind("c", triple, function() {
debug("Centering in screen");
var window = Window.focusedWindow(),
nextScreenFrame = window.screen().frameWithoutDockOrMenu();
centerWindowInFrame(window, nextScreenFrame);
});
api.bind("n", triple, function() {
debug("Center in next screen");
var window = Window.focusedWindow(),
nextScreenFrame = frameOfNextScreen(window);
if (!window || !nextScreenFrame) {
return;
}
if (windowFitsInFrame(window, nextScreenFrame)) {
centerWindowInFrame(window, nextScreenFrame);
} else {
maximizeWindowInFrame(window, nextScreenFrame);
}
});
api.bind("b", triple, function() {
debug("Maximize in next screen");
var window = Window.focusedWindow(),
nextScreenFrame = frameOfNextScreen(window);
if (!window || !nextScreenFrame) {
return;
}
maximizeWindowInFrame(window, nextScreenFrame);
});
api.bind("w", triple, function() {
debug("Moving to top-left");
var win = Window.focusedWindow(),
screenFrame = win.screen().frameWithoutDockOrMenu();
win.setTopLeft({ x: screenFrame.x, y: screenFrame.y });
});
api.bind("l", triple, function() {
debug("Moving to left-half");
var win = Window.focusedWindow(),
screenFrame = win.screen().frameWithoutDockOrMenu();
win.setFrame({
x: screenFrame.x,
y: screenFrame.y,
width: screenFrame.width / 2,
height: screenFrame.height,
});
});
api.bind("r", triple, function() {
debug("Moving to right-half");
var win = Window.focusedWindow(),
screenFrame = win.screen().frameWithoutDockOrMenu();
win.setFrame({
x: screenFrame.x + screenFrame.width / 2,
y: screenFrame.y,
width: screenFrame.width / 2,
height: screenFrame.height,
});
});
api.bind("f", triple, function() {
debug("Focus window on middle 60%");
var win = Window.focusedWindow(),
screenFrame = win.screen().frameWithoutDockOrMenu();
win.setFrame({
x: screenFrame.x + screenFrame.width / 5,
y: screenFrame.y,
width: 0.6 * screenFrame.width,
height: screenFrame.height,
});
win
.otherWindowsOnSameScreen()
.forEach((otherWindow) => otherWindow.app().hide());
});
bindLaunch("/", ["cmd"], "iTerm");
bindLaunch(";", ["cmd"], "Visual Studio Code");
//bindLaunch( '\'', ['cmd'], 'Safari Technology Preview' );
// 1password isn't working with stp80
bindLaunch("'", ["cmd"], "Safari");
bindLaunch("'", ["ctrl"], "Firefox");
bindLaunch(";", ["ctrl"], "Google Chrome Canary");
bindLaunch(".", ["cmd"], "Slack");
bindLaunch(".", ["cmd", "shift"], "Skype");
bindLaunch(".", ["cmd", "ctrl"], "LimeChat");
bindLaunch(";", ["cmd", "ctrl"], "Calendar");
bindLaunch("\\", ["cmd", "ctrl"], "Simplenote");
bindLaunch("\\", ["cmd", "shift"], "zoom.us");
bindLaunch("'", ["cmd", "ctrl"], "Mail");
bindLaunch("'", ["cmd", "shift"], "Mailplane");
bindLaunch("\\", ["cmd"], "Music");
bindLaunch("m", triple, "MPlayer OSX Extended");
bindLaunch("k", ["cmd", "ctrl"], "Keynote");
bindLaunch("x", ["cmd", "ctrl"], "GitX");
bindLaunch("p", ["cmd", "ctrl"], "WordPress.com");
bindLaunch("t", ["cmd", "ctrl"], "Telegram");
bindLaunch("d", ["cmd", "ctrl"], "Deckset");
bindLaunch("r", ["cmd", "ctrl"], "Roam Research");