-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.js
More file actions
218 lines (205 loc) · 6.29 KB
/
Copy pathdefault.js
File metadata and controls
218 lines (205 loc) · 6.29 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
let previousCommand = '', timer = null, mouseTimer = null;
let inputVolume = 60;
Autumn.setStatusMenuItems([
{
title: 'Maximize', onClick() {
Window.focusedWindow().maximize();
} },
{ title: 'Center', onClick() { center() } },
{ title: 'Left', onClick() { setWindow('left') } },
{ title: 'Right', onClick() { setWindow('right') } },
{ title: 'Top', onClick() { setWindow('up') } },
{ title: 'Bottom', onClick() { setWindow('down') }}
]);
const cmdOptShift: ModString[] = ['command', 'option', 'shift']
const cmdShift: ModString[] = ['command', 'shift']
// Restart Autumn (sometimes useful when switching monitors)
Hotkey.activate(cmdOptShift, 'z', () => {
Notification.post({
title: 'Restarting',
subtitle: 'Restarting Autumn',
body: 'Restart initiated'
});
let error = Shell.runSync('killall Autumn & open /Applications/Autumn.app & wait %1 %2');
console.log(error);
});
// Restart WiFi
Hotkey.activate(cmdOptShift, 'w', () => {
Notification.post({
title: 'Restarting WiFi'
});
let error = Shell.runSync('networksetup -setairportpower en0 off');
console.log(error);
error = Shell.runSync('networksetup -setairportpower en0 on');
console.log(error);
});
// Mute toggle
Hotkey.activate(cmdOptShift, '0', () => {
let output = Shell.runSync("osascript -e 'input volume of (get volume settings)'");
let volumeStr = output.stdout;
let currentVolume = parseInt(volumeStr.substr(0, volumeStr.indexOf("\n")), 10);
console.log(`Current volume: ${currentVolume}`);
if (currentVolume < 5) {
console.log('Unmuting');
Notification.post({
title: 'Un-muting'
});
console.log(`Setting input volume to ${inputVolume}`);
let output = Shell.runSync(`osascript -e "set volume input volume ${inputVolume}"`);
console.log(output);
} else {
console.log('Muting');
Notification.post({
title: 'Muting'
});
let output = Shell.runSync(`osascript -e "set volume input volume 0"`);
inputVolume = currentVolume;
console.log(output);
}
});
// Switch to USB input/output
Hotkey.activate(cmdOptShift, '9', () => {
Notification.post({
title: 'Switching to USB audio'
});
let output = Shell.runSync(`/usr/local/Cellar/switchaudio-osx/1.0.0/SwitchAudioSource -t input -s "USB audio CODEC"`);
console.log(output);
output = Shell.runSync(`/usr/local/Cellar/switchaudio-osx/1.0.0/SwitchAudioSource -t output -s "USB audio CODEC"`);
console.log(output);
});
// Switch to AirPods input/output
Hotkey.activate(cmdOptShift, '8', () => {
Notification.post({
title: 'Switching to AirPods'
});
let output = Shell.runSync(`/usr/local/Cellar/switchaudio-osx/1.0.0/SwitchAudioSource -t input -s "Thomas’s AirPods Pro"`);
console.log(output);
output = Shell.runSync(`/usr/local/Cellar/switchaudio-osx/1.0.0/SwitchAudioSource -t output -s "Thomas’s AirPods Pro"`);
console.log(output);
});
// Maximize the window
Hotkey.activate(cmdOptShift, 'm', () => {
Window.focusedWindow().maximize();
});
// Center the window on screen (toggles sizes)
Hotkey.activate(cmdOptShift, 'c', () => {
center();
});
function center() {
let percent = 0.65;
switch (previousCommand) {
case 'centerA' :
percent = 0.85;
previousCommand = 'centerB';
break;
case 'centerB' :
percent = 0.45;
previousCommand = 'centerC';
break;
case 'centerC' :
default :
percent = 0.65;
previousCommand = 'centerA';
break;
}
if (!Window.focusedWindow()) {
return null;
}
Window.focusedWindow().moveToPercentOfScreen({
x: (1 - percent) / 2,
y: 0.0,
width: percent,
height: percent,
})
});
function moveToUnit(x, y, width, height) {
Window.focusedWindow().moveToPercentOfScreen({
x, y, width, height
});
}
// Toggles for taking up halves/quarters of screens
// (hit once with left key to get a window half the width of your display,
// twice to get a window that fills the left half of your display)
function setWindow(command) {
if (!Window.focusedWindow()) {
return null;
}
let screenRect = Screen.currentScreen().innerFrame();
let s = Screen.currentScreen();
let w = Window.focusedWindow();
let winRect = w.size();
switch (command) {
case 'up':
switch (previousCommand) {
case 'upA':
moveToUnit(0, 0, 1, 0.5);
previousCommand = 'upB';
break;
case 'upB':
default:
w.setSize({ height: Math.round(screenRect.height / 2), width: winRect.width });
w.setPosition({ x: w.position().x, y: 0 });
previousCommand = 'upA';
break;
}
break;
case 'down':
switch (previousCommand) {
case 'downA':
moveToUnit(0, 0.5, 1, 0.5);
previousCommand = 'downB';
break;
case 'downB':
default:
w.setSize({ height: Math.round(screenRect.height / 2), width: winRect.width });
w.setPosition({ x: w.position().x, y: Math.round(screenRect.height / 2) });
previousCommand = 'downA';
break;
}
break;
case 'left':
switch (previousCommand) {
case 'leftA':
moveToUnit(0, 0, 0.5, 1);
previousCommand = 'leftB';
break;
case 'leftB':
default:
w.setSize({ height: winRect.height, width: Math.round(screenRect.width / 2) });
w.setPosition({ x: 0, y: 0 });
previousCommand = 'leftA';
break;
}
break;
case 'right':
switch (previousCommand) {
case 'rightA':
moveToUnit(0.5, 0, 0.5, 1);
previousCommand = 'rightB';
break;
case 'rightB':
default:
w.setSize({ height: winRect.height, width: Math.round(screenRect.width / 2) });
w.setPosition({ x: Math.round(screenRect.width / 2), y: 0 });
previousCommand = 'rightA';
break;
}
break;
}
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
previousCommand = '';
clearTimeout(timer);
}, 5000);
}
// Try pressing Cmd+Opt+Ctrl and arrow keys
Hotkey.activate(cmdOptShift, 'up',
() => { setWindow('up') });
Hotkey.activate(cmdOptShift, 'down',
() => { setWindow('down') });
Hotkey.activate(cmdOptShift, 'left',
() => { setWindow('left') });
Hotkey.activate(cmdOptShift, 'right',
() => { setWindow('right') });