summaryrefslogtreecommitdiffstats
path: root/osdep/mac
diff options
context:
space:
mode:
Diffstat (limited to 'osdep/mac')
-rw-r--r--osdep/mac/swift_extensions.swift24
1 files changed, 24 insertions, 0 deletions
diff --git a/osdep/mac/swift_extensions.swift b/osdep/mac/swift_extensions.swift
index ed6c86cd2a..2bb3d4bf7c 100644
--- a/osdep/mac/swift_extensions.swift
+++ b/osdep/mac/swift_extensions.swift
@@ -28,6 +28,30 @@ extension NSScreen {
return deviceDescription[.screenNumber] as? CGDirectDisplayID ?? 0
}
}
+
+ public var serialNumber: String {
+ get {
+ return String(CGDisplaySerialNumber(displayID))
+ }
+ }
+
+ public var name: String {
+ get {
+ // force unwrapping is fine here, regex is guaranteed to be valid
+ let regex = try! NSRegularExpression(pattern: " \\(\\d+\\)$", options: .caseInsensitive)
+ return regex.stringByReplacingMatches(
+ in: localizedName,
+ range: NSRange(location: 0, length: localizedName.count),
+ withTemplate: ""
+ )
+ }
+ }
+
+ public var uniqueName: String {
+ get {
+ return name + " (\(serialNumber))"
+ }
+ }
}
extension NSColor {