-
Notifications
You must be signed in to change notification settings - Fork 2
/
mirror.js
50 lines (43 loc) · 1.08 KB
/
mirror.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
function showError(err) {
const app = Application.currentApplication();
app.includeStandardAdditions = true;
app.displayAlert(err.toString());
}
function getDisplaysPane(prefApp) {
const displays = prefApp.panes.byId('com.apple.preference.displays');
displays.reveal();
delay(0.3);
return displays;
}
function getPrefWindows(prefName) {
return new Application('System Events')
.processes[prefName]
.windows();
}
function mirror(displays, prefApp, prefWindows) {
try {
displays
.anchors
.byName('displaysArrangementTab')
.reveal();
} catch (err) {
showError(err, 'Cannot find Arrangement');
return;
}
prefWindows
.map(w => w.tabGroups[0])
.filter(t => t.checkboxes.length > 0)
.forEach(t => t.checkboxes[0].click());
}
function run(argv) {
const prefName = 'System Preferences';
const prefApp = new Application(prefName);
const displays = getDisplaysPane(prefApp);
const prefWindows = getPrefWindows(prefName);
if (prefWindows.length > 1) {
mirror(displays, prefApp, prefWindows);
} else {
showError('Need more displays', '');
}
prefApp.quit();
}