-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathorientation.jxa
More file actions
53 lines (41 loc) · 1.58 KB
/
orientation.jxa
File metadata and controls
53 lines (41 loc) · 1.58 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
const app = Application.currentApplication();
app.includeStandardAdditions = true;
const sp = Application("System Preferences");
const se = Application("System Events");
const findWindow = (systemEvents, displayName) => {
return se.processes['System Preferences'].windows.byName(displayName);
}
const findPopupButton = (display, name) => {
return display.tabGroups[0].popUpButtons.byName(name)
}
const rotateDisplay = (systemEvents = se, display, popup, orientation = 'Standard', timeout = 3) => {
popup.click();
systemEvents.keystroke(orientation);
systemEvents.keyCode(36);
// Wait for screen flash from orientation switch
delay(timeout);
// Click orientation confirmation button
const sheets = display.sheets;
if (sheets.length) {
const confirmation = sheets[0].buttons.byName('Confirm');
return confirmation.enabled() && confirmation.click();
}
};
// Bring Display Window Forward
sp.activate()
// Bring 'Displays' to the foreground
sp.panes["com.apple.preference.displays"].reveal();
// Find the primary display
const standardDisplay = findWindow(se,'DELL U2717D (1)');
// Find the drop down for orientation
const standardRotation = findPopupButton(standardDisplay, 'Rotation:');
// Rotate
rotateDisplay(se, standardDisplay, standardRotation);
// Find the second display
const rotatedDisplay = findWindow(se, 'DELL U2717D (2)')
// Find the drop down for orientation
const rotatedRotation = findPopupButton(rotatedDisplay, 'Rotation:');
// Click drop down and select orientation by keystroke
rotateDisplay(se, rotatedDisplay, rotatedRotation, '90');
// Clean Up
sp.quit();