-
Notifications
You must be signed in to change notification settings - Fork 9
/
RotateDisplay.swift
49 lines (38 loc) · 1.45 KB
/
RotateDisplay.swift
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
import Cocoa
import ColorSync
import Foundation
func rotateDisplay(display: MPDisplay, orientation: Int32) {
let id = display.displayID
let name = display.name
guard display.canChangeOrientation() else {
print("\nThe display does not support changing orientation: \(name) [ID: \(id)]")
return
}
print("\nChanging orientation for \(name) [ID: \(id)]: \(display.orientation) -> \(orientation)")
display.orientation = orientation
}
func printDisplays(_ displays: [MPDisplay]) {
print("ID\tUUID \tCan Change Orientation\tOrientation\tName")
for panel in displays {
print(
"\(panel.displayID)\t\(panel.uuid?.uuidString ?? "")\t\(panel.canChangeOrientation()) \t\(panel.orientation)° \t\(panel.name)"
)
}
}
func main() {
guard let mgr = MPDisplayMgr(), let displays = mgr.displays as? [MPDisplay] else { return }
printDisplays(displays)
guard CommandLine.arguments.count >= 3, let orientation = Int32(CommandLine.arguments[2]),
[0, 90, 180, 270].contains(orientation)
else {
print("\nUsage: \(CommandLine.arguments[0]) <id-uuid-or-name> 0|90|180|270")
return
}
let arg = CommandLine.arguments[1]
guard let display = mgr.matchDisplay(filter: arg) else {
print("\nNo display found for query: \(arg)")
return
}
rotateDisplay(display: display, orientation: orientation)
}
main()